Modifying Rhino Options with a Python script

Hi @clement and @dale,

I’m trying to modify the very helpful code you provided in another thread @clement to now delete paths from Options->RhinoScript->Startup , located here via the UI

but I can’t figure out how to access “RhinoScript” in “Options” with my python script. My code below, fails on this line

settings = settings.GetChild("Options").GetChild("RhinoScript")

because “RhinoScript” is not a child of “Options”. I’ve tried googling around but I don’t understand where it is nor do I understand how to list all the children and strings within the PersistentSettings class, can you help? Thank you!


def RemoveRhinoScriptStartupPath(path):
    '''removes a command from rhinoscript startup path list'''
    
    path = path.lower()
    
    rhino_id = Rhino.RhinoApp.CurrentRhinoId
    settings = Rhino.PlugIns.PlugIn.GetPluginSettings(rhino_id, False)
    settings = settings.GetChild("Options").GetChild("RhinoScript")
    paths =  settings.GetString("Startup").splitlines()
    
    if path and path in paths: 
        paths.remove(path)
        settings.SetString("Startup", "\n".join(paths))

I see the confusion, unfortunately they decided to put multiple plugin settings within the Options UI, so you need to get the settings specific to the RhinoScript plugin for your scenario:

These are the key/values available within the RhinoScript Plugin Settings. You can use these similar to the way the General options work on the Rhino App plugin.

2 Likes

Amazing! Thank you @jstevenson :slight_smile:

With your help I can now print the settings as a list and modify that list, but I have a new issue where it appears that none of the changes I make are actually being applied.

In the below code, I attempt to modify the settings, and then I print the StartupFileList again to confirm that it has been modified, it appears to be successful. But, the actual setting is not being updated in Rhino Options (even with a Rhino restart). The paths persist and I can’t seem to update the setting. Am I not saving or pushing the change correctly? Also asking @dale because I see he wrote a related guide

Here is my code:

def removeRhinoScriptStartupPath(path):
    '''removes a command from rhinoscript startup path list'''
    
    path = path.lower()
    
    # Get the startup script paths
    rhinoscript_id = Rhino.PlugIns.PlugIn.IdFromName("RhinoScript")
    settings = Rhino.PlugIns.PlugIn.GetPluginSettings(rhinoscript_id, False)
    raw_paths = settings.GetString("StartupFileList")
    print("Raw paths:", raw_paths)
    paths = re.findall(r"<value>(.*?)</value>", raw_paths)
    print("Extracted paths:", paths)
    
    # Remove the desired path
    for item in paths:
        print("Checking item:", item)
        if item.lower() == path:
            print("Found match. Removing:", item)
            paths.remove(item)
            break  # Stop after removing one match

    # Reconstruct the structure
    updated_paths = "<list>" + "".join(["<value>{0}</value>".format(p) for p in paths]) + "</list>"
    print("Updated paths:", updated_paths)
    
    # Save the updated settings
    settings.SetString("StartupFileList", updated_paths)
    Rhino.PlugIns.PlugIn.SavePluginSettings(rhinoscript_id) #?
    Rhino.PlugIns.PlugIn.RaiseOnPlugInSettingsSavedEvent()  #?
    
    # Print to confirm settings updated
    check_paths = settings.GetString("StartupFileList")
    print ("Check paths:", check_paths)


removeRhinoScriptStartupPath("Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\WakeUp3XN.rvb")

and here is what is printing - seems to be working:

('Raw paths:', '<list><value>Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\WakeUp3XN.rvb</value><value>Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\FindSameNameGh.rvb</value></list>')
('Extracted paths:', ['Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\WakeUp3XN.rvb', 'Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\FindSameNameGh.rvb'])
('Checking item:', 'Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\WakeUp3XN.rvb')
('Found match. Removing:', 'Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\WakeUp3XN.rvb')
('Updated paths:', '<list><value>Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\FindSameNameGh.rvb</value></list>')
('Check paths:', '<list><value>Y:\\00 Digital Group\\Deploy\\Web_Player\\Commands\\_Hidden\\FindSameNameGh.rvb</value></list>')

But the setting is not actually being updated:

Thanks in advance!

maybe a bug ?
if you go to Rhino Options
→ Advanced
→ RhinoScript.StartUpFileList
there is a pop up dialog that allows changes to the list as well.
but also those changes are not saved …

2 Likes

True! Well spotted, it does seem like a bug

This is not a bug - RhinoScript simply doesn’t support modifying it’s startup list in this way.

This works in Rhino 7.

import Rhino

__RHINOSCRIPT__ = "1c7a3523-9a8f-4cec-a8e0-310f580536a7"

def DeleteStartupScripts():
    rhinoScript = Rhino.RhinoApp.GetPlugInObject(__RHINOSCRIPT__)
    if rhinoScript:
        startupList = rhinoScript.StartupScriptList()
        if startupList:
            for script in startupList:
                rhinoScript.DeleteStartupScript(script)

if __name__=="__main__":  
    DeleteStartupScripts()

– Dale

3 Likes

Amazing, thanks Dale!

For anyone else’s reference here is my updated code:

def deleteRhinoScriptStartupScript(path):
    '''Removes a script from the RhinoScript startup script list.'''
    deletedPath = False
    try:
        if path:
            path = path.lower()

            # Get the RhinoScript plugin object
            rhinoScript_Id = Rhino.PlugIns.PlugIn.IdFromName("RhinoScript")
            rhinoScript = Rhino.RhinoApp.GetPlugInObject(rhinoScript_Id)

            # Remove the script if it exists in the startup list
            if rhinoScript:
                startupList = rhinoScript.StartupScriptList()
                if startupList:
                    for script in startupList:
                        if script.lower() == path:
                            rhinoScript.DeleteStartupScript(script)
                            deletedPath = True
    except Exception as e:
        try:
            print("Error in deleteRhinoScriptStartupScript: " + str(e))
        except Exception:
            print("Error in deleteRhinoScriptStartupScript: An unknown error occurred.")
    return deletedPath
2 Likes