But I want to add the startup command from a Python script (or rvb script). I am implementing this change on many users’ machines and would like to have the startup commands added or removed from a script.
I saw on the forums how to update the PackageManger source setting in python:
settings = Rhino.PlugIns.PlugIn.GetPluginSettings(Rhino.RhinoApp.CurrentRhinoId, False)
s = settings.GetChild("Options").GetChild("PackageManager")
s.SetString("Sources","https://yak.rhino3d.com;" + packageFolder)
But I cannot figure out how to adapt this code to edit the startup commands. Can anyone help?
I couldn’t get Rhino to run a py script from the startupscriptlist but thanks to your links I came up with a bit of a clunky workaround that is doing what I need.
If it helps anyone in the future: I have an .RVB script that calls the command that I want:
Option Explicit
Sub WakeUp()
Dim commandName
commandName = "GoodMorning"
Rhino.Command commandName
End Sub
WakeUp
I am using another RVB script to add the initial script to the startup script list, I would have preferred to do this with python but I could only access AddStartupScript through RVB:
Option Explicit
Sub StartupEnable()
Dim filePath
filePath = "C:\my file\path here\WakeUp.rvb"
Rhino.AddStartupScript(filePath)
End Sub
StartupEnable
I can then finally call the StartupEnable script from python to add the command to the startup script list:
If it helps anyone, there is a way to add startup commands purely in python without that clunky RVB step. Here is the function I now use to add startup commands
def addStartupCommand(str_cmd):
'''Adds a new command to the startup command list.'''
addedCommand = False
try:
if str_cmd:
str_cmd = str_cmd.lower()
# Get settings for startup commands
rhino_id = Rhino.RhinoApp.CurrentRhinoId
settings = Rhino.PlugIns.PlugIn.GetPluginSettings(rhino_id, False)
settings = settings.GetChild("Options").GetChild("General")
# Fetch existing commands and add if not present
commands = settings.GetString("StartupCommands").splitlines()
if str_cmd and str_cmd not in commands:
commands.append(str_cmd)
settings.SetString("StartupCommands", "\n".join(commands))
addedCommand = True
except Exception as e:
try:
print("Error in addStartupCommand: " + str(e))
except Exception:
print("Error in addStartupCommand: An unknown error occurred.")
return addedCommand
And here is the function to delete them
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
I might not be the right person to ask since I started coding in python but I prefer coding everything in python. Especially since the ScriptEditor doesn’t support RVB