Advertisement
Guest User

sc2_adjust_object_heights.py

a guest
Oct 6th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.89 KB | None | 0 0
  1. import sys
  2. from decimal import Decimal
  3. import xml.etree.ElementTree as xml
  4.  
  5. def adjust_positions(objects, x, y, z):
  6.     adjustments = 0
  7.     for unit in objects.getchildren():
  8.         if unit.tag not in ['ObjectDoodad', 'ObjectUnit', 'ObjectPoint']:
  9.             print 'unsupported tag: %s'%unit.tag
  10.             continue
  11.         position = unit.attrib['Position']
  12.         position = map(Decimal,position.split(','))
  13.         position[0] += x
  14.         position[1] += y
  15.         position[2] += z
  16.         position = ','.join(map(str,position))
  17.         unit.attrib['Position'] = position
  18.         adjustments += 1
  19.     print 'adjusted %d units'%adjustments
  20.     return objects
  21.  
  22. if __name__ == '__main__':
  23.     if len(sys.argv) < 2:
  24.         print 'usage: %s <Objects filename>'%sys.argv[0]
  25.         sys.exit(0)
  26.     filename = sys.argv[1]
  27.     objects = xml.parse(filename).getroot()
  28.     objects = adjust_positions(objects,0,0,5) # bump objects up 5 units
  29.     open(filename,'wb').write(xml.tostring(objects))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement