Skip to content

Instantly share code, notes, and snippets.

@WNP78
Last active February 4, 2021 23:54
Show Gist options
  • Save WNP78/18bd69c73fa0cfb65c2d71bff323c5aa to your computer and use it in GitHub Desktop.
Save WNP78/18bd69c73fa0cfb65c2d71bff323c5aa to your computer and use it in GitHub Desktop.
import sys,os
def tryFindSpDir():
if sys.platform.startswith("win"):
p = os.path.abspath(os.path.join(os.getenv("APPDATA"),"..\\LocalLow\Jundroo\SimplePlanes\AircraftDesigns")) + "\\"
if os.path.isdir(p): return p
elif sys.platform.startswith("darwin"): # MacOS - not tested
p = os.path.abspath("~/Library/Application Support/Jundroo/SimplePlanes/AircraftDesigns") + "/"
if os.path.isdir(p): return p
return input("SP aircraft directory> ") # failed to auto detect
from xml.etree.ElementTree import ElementTree as et
path = os.path.join(tryFindSpDir(), input("Name> ") + ".xml")
tree = et(file=path)
root = tree.getroot()
prop = input("Property> ")
val = input("Value> ")
for part in root.findall("Assembly/Parts/Part"):
part.set(prop, val)
tree.write(path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment