Script files to load when Rhino starts

No, I meant in the Python editor itself… But now, rereading the whole thread I’m not sure whether you’re looking for a way to set file paths (what I showed) or a way to run startup scripts. As far as I know the only way to run Python scripts at startup currently is in Options>General to set them as startup commands with

! _-RunPythonScript scriptfilename.py

and have previously set a path to the folder where the script is in the Python editor as above, or have the full pathname in the command.

–Mitch

1 Like

Hi Steve,

Just trying to have all the stuff in the same place so it’s easier to find for the user, it seems odd to be able to set paths to where Rhinoscript can find files in Rhino options, and not be able to do the same thing with Python scripts.

–Mitch

Yes, I thought running Python scripts at Rhino startup.
Thanks Mitch.

I’m pretty confused about this thread. There seem to be about three different topics being discussed.

With respect to python
1 - Why do you want to run a python script when starting Rhino? Does anyone have an example of why they would want to do this? Does “-RunPythonScript myscript.py” work for people? I’m just confused and need help.

2 - I can see the confusion about python not looking in the folders specified by the “Rhino Search Paths”. I can change this for Rhino 6 and see if that makes more sense for users (thanks.)

Thanks,
-Steve

Hi Steve.

I opened that issue at github. Sorry for duplicating it with already present ones.

  1. There is no specific reason, at least from my side. I just wanted to run some small script which will add text string to the document, then explode it to curves. Like “Merry Christmas” or something similar. Just a play-around really.
  2. Adding the folder where Rhino startup .py is located to the “Module Search Paths” (inside of Rhino Python Editor) and then adding the name of that specific Rhino startup .py to Rhino Command list (_-RunPythonScript “startup.py”) worked perfectly.
    I also checked the option with supplying the full path, instead of adding the folder location to “Module Searc Paths” - it worked too.
    Just like Mitch explained.

Ok, thanks. I’m not going to make any changes with respect to python and start-up scripts then.

Pascal is this something that can be called outside of Rhino?

I would like to run a startup script that populates the user’s Grasshopper template directory field with a server location. This way the user would always have the latest Grasshopper template upon starting Rhino.

The reason I’d like to call this outside of Rhino is so that the script is automatically referenced within the Rhino Options > RhinoScript > Startup field upon the user’s installation of Rhino.

If I can’t let me know what you suggest, for example I could make a toolbar button using Rhino.AddStartupScript() to take care of this.

A use case could be to register an alias.
So when Rhino starts up a command is registered that can call the script.
Like in this rvb file:
http://discourse.mcneel.com/t/reset-or-change-block-instances-transformations-scale-rotation/10786/3?u=ejnaren

Hi pascal,
how would I add every script from a specific folder?
Thanks,
phillip

Hi @phillip,

Create a script that allows you to select a folder. Then iterate all the files in the folder and added the .rvb files to the list of scripts to load at start using Rhino.AddStartupScript.

– Dale

Could someone walk me down the process of adding a python script to rhino (loading it at startup) and then assigning a shortcut to the said python script. I mean, is this possible with Rhino 5 (for windows)? I’m aware there is a wish/effort to combine .rvb and .py scripts at start-up in rhino 6 but I was just curious, thanks. Or a relevant blog post would be very useful as well. Thank you, noob out.

1 Like

It’s not possible to add python scripts to your startup scripts like you can with .rvb’s.

You can make it work like this:

  1. Put the script somewhere on your hard drive.
  2. Create an alias to the script ! _-RunPythonScript "full-path-to-script-file"
  3. Put the alias you just created in your startup commands (not scripts) in Options>General

The script should run every time you start Rhino then.

HTH, --Mitch

1 Like

Mitch, thanks for the prompt response. One more thing to clear, does this process load the script to be recalled later during the session and attach aliases to it? I’m doubtful but hopeful :slight_smile: anyhow my follow-up question is if you have these scripts in .rvb format then? Thank you!

No, but you did that manually in step 2. So if you type the alias at any time the script will run. --Mitch

Oh I see got it, thank you breaking it down, have a good one.

Any idea why this there isn’t an easier way in Rhino to create aliases for python scripts? Most users I deal with prefer keyboard commands rather than buttons.

It’s not all that hard… Yes, it would be easier to drag and drop, but having set a path to the scripts folder (once) in the editor, all you need to do is throw the script file into that folder and then make your alias.

Your help is much appreciated!

Here is some complete info…

https://wiki.mcneel.com/developer/macroscriptsetup

It looks like a lot, but it’s only a couple minutes for the initial setup of the paths.

Mine looks like this:

Call StartUp()
Sub StartUp()
Call ClearStartUp()
Rhino.AddStartUpScript “PATH\TO\MY\FOLDER_StartUp.RVB”
Call AddStartupScript()

End Sub

Function ClearStartUp()

Dim intCount, arrPaths, strPath

intCount = Rhino.StartupScriptCount

If intCount > 0 Then

	arrPaths = Rhino.StartupScriptList

	For Each strPath In arrPaths

		Rhino.DeleteStartupScript(strPath)

	Next

End If

End Function

Function AddStartupScript()

Dim fso, f, f1, fc, s
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.GetFolder("PATH\TO\MY\OTHER\FOLDER\FULL\OF\SCRIPTS")
Set fc = f.Files
For Each f1 In fc
	s = f & "\" & f1.name 
			
	Rhino.AddStartupScript s
	
	
Next

End Function