Jump to content

Change Tool settings by Script


DomC

Recommended Posts

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))

 

Link to comment

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...