Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import xml.etree.ElementTree as ET
- import os,sys,time
- class ProgressBar():
- def __init__(self,title):
- global progress_x
- sys.stdout.write(title + ": [" + "-"*40 + "]" + chr(8)*41)
- sys.stdout.flush()
- progress_x = 0
- def setprog(self,x):
- global progress_x
- x = int(x * 40 // 100)
- sys.stdout.write("#" * (x - progress_x))
- sys.stdout.flush()
- progress_x = x
- def end(self):
- sys.stdout.write("#" * (40 - progress_x) + "]\n")
- sys.stdout.flush()
- def subE(st):
- if "E" in st:
- st = st.split("E")
- assert len(st) == 2
- st = float(st[0])*(10**int(st[1]))
- return st
- def gi(p):
- try:return raw_input(p)
- except NameError:return input(p)
- def tryAuto():
- appd = os.environ["APPDATA"]
- d = os.path.join(os.path.dirname(appd),"LocalLow","Jundroo","SimplePlanes","AircraftDesigns")
- if os.path.isdir(d):
- return d
- else:
- return 0
- spDir = tryAuto()
- if spDir == 0:spDir = gi("SP Aircraft Directory>")
- for ln in os.listdir(spDir):
- if ln.endswith(".xml"):
- pass#print(ln[:len(ln)-4:])
- infile = gi("Aircraft name>")+".xml"
- infile = os.path.join(spDir,infile)
- outfile = infile#os.path.join(spDir,gi("Output name>")+".xml")
- tree = ET.parse(infile)
- toScale = gi("Scale>")
- if toScale == "": toScale = [gi("xScale>"),gi("yScale>"),gi("zScale>")]
- else: toScale = [toScale,toScale,toScale]
- root = tree.getroot()
- pth = ["Assembly","Parts"]
- cd = root
- for s in pth:
- for ite in cd:
- if ite.tag == s:
- cd = ite
- break
- assert cd.tag == "Parts"
- p=1
- tp=len(cd)
- pb=ProgressBar("Sacling...")
- for part in cd:
- pb.setprog((p/tp)*100)
- eng = False
- prop= False
- pos = part.attrib["position"]
- if "scale" in part.attrib:
- scale = part.attrib["scale"]
- else:
- scale = "1,1,1"
- if "massScale" in part.attrib:
- massScale = part.attrib["massScale"]
- else:
- massScale = 1.0
- fuel = False
- for chld in part:
- if chld.tag == "Engine.State":
- eng = chld
- if "powerMultiplier" in chld.attrib: powerMultiplier = chld.attrib["powerMultiplier"]
- else: powerMultiplier = 1
- if "exhaustScale" in chld.attrib: exhaustScale = chld.attrib["exhaustScale"]
- else: exhaustScale = "1,1,1"
- elif chld.tag == "PropEngineAdvanced.State":
- prop = chld
- pPower = chld.attrib["power"]
- elif chld.tag == "FuelTank.State":
- fuel = chld
- fuelA,fuelC = fuel.attrib["fuel"],fuel.attrib["capacity"]
- if eng == False:
- powerMultiplier = False
- exhaustScale = False
- pos = pos.split(",")
- assert len(pos) == 3
- scale = scale.split(",")
- assert len(scale) == 3
- if exhaustScale != False:
- exhaustScale = exhaustScale.split(",")
- assert len(exhaustScale) == 3
- for i in range(0,3):
- ts = float(toScale[i])
- pos[i],scale[i] = subE(pos[i]), subE(scale[i])
- pos[i] = float(pos[i]) * ts
- scale[i] = float(scale[i]) * ts
- if exhaustScale != False:exhaustScale[i] = float(exhaustScale[i]) * ts
- cubeMulti = float(toScale[0]) * float(toScale[1]) * float(toScale[2])
- if powerMultiplier != False:powerMultiplier = float(powerMultiplier) * cubeMulti
- if prop != False: pPower = float(pPower) * cubeMulti
- if fuel != False: fuelA,fuelC = float(fuelA) * cubeMulti, float(fuelC) * cubeMulti
- massScale = float(massScale) * float(toScale[0]) * float(toScale[1]) * float(toScale[2])
- part.set("position", ( str(pos[0]) + "," + str(pos[1]) + "," + str(pos[2]) ) )
- part.set("scale", ( str(scale[0]) + "," + str(scale[1]) + "," + str(scale[2]) ) )
- part.set("massScale", str(massScale))
- if powerMultiplier != False:
- eng.set("powerMultiplier",str(powerMultiplier))
- if exhaustScale != False:
- eng.set("exhaustScale" ,str(exhaustScale[0]) + "," + str(exhaustScale[1]) + "," + str(exhaustScale[2]))
- if prop != False:
- prop.set("power", str(pPower))
- if fuel != False:
- fuel.set("fuel",str(fuelA))
- fuel.set("capacity",str(fuelC))
- pb.end()
- tree.write(outfile)
- gi("File Saved: "+outfile)
Advertisement
Add Comment
Please, Sign In to add comment