Using %homepath% in a rhino button

I am trying to run a python script with a Rhino button, and I want to make this available to lots of people. My plan was to store the python scripts and toolbar in a git repository, with instructions for people to clone the folder to their Documents folder.

On the Button I would then have the command:

!-RunPythonScript (“C:%HOMEPATH%\Documents\testPath\”)

I’ve tried a number of variations, but cant get this to work. %homepath% doesn’t seem to be working in the command line like this.

Does anyone know how to get this to work? Or have any better ways of sharing Python scripts being run by buttons?

Hi Josh - try without the C: in front, just %HOMEPATH%

Hm, yeah, I can’t get that to work either so far.

BTW, @JoshD - you need a space after the “!”

! -RunsPythonScript not !-RunPythonScript


Hi @JoshD,
You can use this:

import os
homepath = os.path.expanduser('~')
my_path = r'Documents\testPath\'
total_path = os.path.join(homepath, my_path)

You can include this in a separate launcher script or put it all together, separating the lines with semicolons, in your RunPythonScript call

Or use an installer

1 Like

Hi @Dancergraham, thanks for the two ideas. I dont know if im misunderstanding the suggestion or perhaps I’ve not been clear on my goal. Im trying to run my python script with a button, so it is just the macro language that is available in the buttons I believe. Therefore I dont think I can import etc. ?

Creating the Rhino Commands may be a better road to go down. I’ll need to edit all my scripts and the toolbar, but it looks like it may be a good solution. Thanks for pointing this out, looks like its probably what I should have started with in the first place.

I reported this here.

More of a request :wink:

1 Like

Thanks for trying, and logging that. Would be a good feature I think.

It’s possible but a little convoluted and i didn’t get my head around it fully previously :slight_smile: I’ve now got it working…
I put the sample file ‘’ in a folder called ‘test’ in my home directory. I then put the following line in a button:
! -_RunPythonScript "import os;import imp;homepath = os.path.expanduser('~');my_path=r'test\';imp.load_source('HelloPython', os.path.join(homepath,my_path))"
This runs the HelloPython file :champagne:


Oww. My brain.


1 Like

Ah yes, I see. Run a python script that runs a python script. Nice idea. Thanks :smile:
Thanks for the help.
I’ve been trying to get the plugin’s to work as per your suggestion. But getting a bit stuck at it as Im getting an ‘unexpected error’ in the Install Wizard.
So I may revert back to this plan.

A little off thread, but to close out the plugin side of things.
Can I have multiple commands in one plugin? I would guess yes, but this isnt clear from the instructions.


Is the title the name of the command or the plugin? Again im guessing the plugin, but if so, the example is a little confusing. And can I make the title whatever I want or does it need to be the same as before? Trying to figure out if one of these things is maybe giving me my error.

from the link :

You can add multiple commands to a plugin

Looks like it, but that doesnt make sense if there are multiple commands… hmm…?

Just tested, and it works great. :+1:

Not clear what I was doing wrong with the plugin, following the instructions, but found the RhinoScriptCompiler, and that worked great with my tests.

Great - I think that’s the best option for your use