algorithmic modeling for Rhino
I just wanted to start a discussion about best practices and possibilities with regard to making Grasshopper plugins using Python.
In this case, I'm using the term "plugin" loosely, because currently the GhPython scripting component for Rhino 5 is the only means of running Python in Grasshopper.
How should one package a python script for other users if that script depends on additional modules or packages?
For example, the shapefile reading script that I recently wrote depends on a set of modules, and I want to find a way to offer them to users without forcing them to edit sys.path. I also want to respect the basic organization setup for plugins in Grasshopper, and therefore python packages could be placed in the Compnents Folder (if that seems appropriate) or elsewhere. Perhaps the Components folder could be a default folder on sys.path for the gh python component?
Thanks,
Ben
Tags:
Hi Benjamin,
yes, good ideas here and the options you mention do not necessarily exclude one another.
>How should one package a python script for other users if that script depends on additional modules or packages?
At the moment I think the user should know how to add the module path to sys.path. It's just two-three lines. This simpler approach should always work. But then again...
>I also want to respect the basic organization setup for plugins in Grasshopper, and therefore python packages could be placed in the Compnents Folder (if that seems appropriate) or elsewhere.
That folder or one close to it might be good. However, I would just try to keep this as a second choice because it would quickly become difficult to maintain different versions of the same module, especially if they are necessary in different definitions.
There is also the option of having the path of the .ghx file (possibly + '\modules\') automatically added to sys.path. This would also make it simple to maintain different versions on the same machine.
Also, would it be an option to have the possibility to embed directly the whole module within the GhPython component itself? If there are just a couple referenced files, this would probably be the easiest for final users to run the definition.
- Giulio
_______________
giulio@mcneel.com
McNeel Europe
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2025 Created by Scott Davidson.
Powered by