Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- from decimal import Decimal
- import xml.etree.ElementTree as xml
- def adjust_positions(objects, x, y, z):
- adjustments = 0
- for unit in objects.getchildren():
- if unit.tag not in ['ObjectDoodad', 'ObjectUnit', 'ObjectPoint']:
- print 'unsupported tag: %s'%unit.tag
- continue
- position = unit.attrib['Position']
- position = map(Decimal,position.split(','))
- position[0] += x
- position[1] += y
- position[2] += z
- position = ','.join(map(str,position))
- unit.attrib['Position'] = position
- adjustments += 1
- print 'adjusted %d units'%adjustments
- return objects
- if __name__ == '__main__':
- if len(sys.argv) < 2:
- print 'usage: %s <Objects filename>'%sys.argv[0]
- sys.exit(0)
- filename = sys.argv[1]
- objects = xml.parse(filename).getroot()
- objects = adjust_positions(objects,0,0,5) # bump objects up 5 units
- open(filename,'wb').write(xml.tostring(objects))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement