DomC Posted October 25, 2024 Share Posted October 25, 2024 Hi What i am trying to do is, change tool settings by script. The Following approaches i try: 1. SetSavedSetting() This works, but it seems it writes to the xml memory. And while closing Vectorworks the settings are wrote back to the file. Also i can set every setting i want as Example vs.SetSavedSettings('foo', 'bar', 100) It will store that setting 2. Second approach Writing the xml file. Which also works. It writes the value with my example. But after closing Vectorworks it will overwrite with the tool setting. any ideas? import os import xml.etree.ElementTree as ET # Hauptskript user_app_settings = vs.GetFolderPath(-15) tool_settings_file = os.path.join(user_app_settings, 'SavedSettings.xml') s_dialog = 'Einstellungen optimieren' #res = vs.YNDialog(s_dialog) import xml.etree.ElementTree as ET def modify_nested_xml_value(file_path, parent_tag, key, new_value): # Parse the XML file tree = ET.parse(file_path) root = tree.getroot() # Suche nach dem übergeordneten Tag und dann nach dem spezifischen Element innerhalb davon parent = root.find(f".//{parent_tag}") if parent is not None: element = parent.find(key) if element is not None: element.text = str(new_value) # Setze den neuen Wert # Speichere das aktualisierte XML zurück in die Datei tree.write(file_path, encoding="UTF-8", xml_declaration=True) vs.Message(f"Updated '{key}' under '{parent_tag}' to '{new_value}' in {file_path}") parent_tag = "DoubleLinePreferences" key = "Separation" new_value = "19" # Neuer Wert für Separation modify_nested_xml_value(tool_settings_file, parent_tag, key, new_value) vs.SetSavedSetting('DoubleLinePreferences', 'Separation', 20) res = vs.GetSavedSetting('DoubleLinePreferences', 'Separation') vs.AlrtDialog(str(res)) Quote Link to comment
DomC Posted October 25, 2024 Author Share Posted October 25, 2024 Got it vs.SetDLSeparation(separationDistance) Quote Link to comment
JBenghiat Posted October 31, 2024 Share Posted October 31, 2024 Just to follow up on your original question (though I'm not entirely sure what the question is), SetSavedSetting() would be what you want, and that seemed to be working for you. Saved settings reside in memory, and then write on quit, and read on the next open. Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.