Best Python/Grasshopper Script Library

As the title suggests, where I can I find a large script library of python definitions? Examples of simple commands such as UV Surface Grid, Divide Curve, etc…
Thanks

Hi,
Simple examples linked from here


Lots of more complex samples here, many including a Python version

Also search this forum, eg ‘import rhinoscriptsyntax as rs’ export mesh

1 Like

I have a similar issue. I am trying to write python code using library calls to rhinoscript, but I cannot find a list of rhinoscript methods for python. C# and VB are shown in the SDK but no Rhino. I have tried guessing the mapping of method names but I cannot get things to work, and I never know if I am failing because I got the name wrong or because the method is not available in grasshopper python.
I would like to RTFM.
Where is it for rhinoscript and rhinocommon method calls from python?
Thanks in advance.

Hello Harvey,

The rhinoscriptsyntax methods are fully listed here

https://developer.rhino3d.com/api/RhinoScriptSyntax/

I might be misunderstanding your question…
rhinoscript is written in python. You can actually look at them by navigating to them on your computer. something like this:
C:%userprofile%\AppData\Roaming\McNeel\Rhinoceros\6.0\Plug-ins\IronPython (814d908a-e25c-493d-97e9-ee3861957f49)\settings\lib\rhinoscript

Rhinoscript is a bunch of python scripts, that under the hood, use rhinocommon.

As pointed out above, there is lots of documentation/examples on how to use rhinoscriptsyntax

As far a s a manual, sounds like this might be a good place to start.
https://www.rhino3d.com/download/ironpython/5.0/rhinopython101

I don’t think there is a full FM for the Python implementation of Rhinocommon. :wink: some Rhinocommon methods are not implemented in Python, I believe.

You can find the implemented methods and attributes by print dir(obj) on it. You can get the source code of a rhinoscriptsyntax function with

import inspect
inspect.getsource(rs.function)
1 Like

This is all great and on-point; I am writing some matrix intensive routines and I need to see what I can use in the libs vs. what I need to write.
From what Chris says I should be able to reference routines in python that are not available in the GH panel, which gives me everything.

What do you mean by “not available in the GH panel”? Can you give an example of what you are trying to accomplish? I think I may be misunderstanding.
In a ghpython component, you can obviously reference in a variety of libraries. The obvious ones will show up in autocomplete when you type “import” followed by a space.
Beyond that, there are other ways to get “SOME” external libraries loaded, but this is not a guarantee that ALL python libraries will work, (since we are really working with ironpython). For example, there are many threads asking about using Numpy, (which…has some very handy matrix functions). BUT…it doesn’t work in a ghpython component. That’s a limitation of ironpython, not Grasshopper/Rhino.

Rhinoscriptsyntax is very well documented and fairly clear in its useage. With that said…Most of us will generally recommend trying to avoid using rhinoscriptsyntax in a ghpython component, and stick directly with rhinocommon. (you can totally use rhinoscriptsyntax in a ghpython component, you just need to be aware of the whole scriptcontext issue…which…you almost never have to worry about if your are using rhinocommon.

again…I am fairly certain I am missing the intent of your question…

I am not religious about Rhinocommon vs. Rhinoscript. In the tutorials and video example Rhinoscript features more than rhinocommon, so I was using what was documented/available.
It was my understanding that things not available in the grasshopper panel would not be available to python. This is not true. But the documentation is still hard:
For example, if I look at the GH Panel I see a Transformation function for “rotating an object in a plane”, where a point and a vector define the plane and rotation orientation and a radian angle sets the magnitude. Finding the equivalent function(s) in the rhinoscript python library is hard. The correct answer begins with XformRotation2 (which uses degrees?!) plus a routine for using the matrix produced to transform the object geometry (which I have not found yet.)
To use Rhinocommon components/methods to script in python, where should I look for the library and syntax, the Rhinocommon equivalent to the excellent https://developer.rhino3d.com/api/RhinoScriptSyntax/ link?

Rhinocommon is documented in the api:
https://developer.rhino3d.com/api/RhinoCommon/html/R_Project_RhinoCommon.htm#!
Not all methods have examples, but quite a few do.
I’m afraid I still don’t understand what you mean by “not available in the grasshopper panel”. do you mean the ghpython editor window? Or do you mean a native grasshopper component that is available to be placed on the grasshopper canvas? I’m pretty sure that most, if not all NATIVE grasshopper components, that require an angle input, always require radians. ( I don’t know what XformRotation2 is…)
There is no “map” of equivalent functions in rhinoscriptsyntax VS rhinocommon.
Do you have something that resembles an example? Perhaps it would be easier to describe?

There is certainly no way to know whether a GrassHopper button relates to a single Python function or Rhinocommon method or rather to a sophisticated combination of Rhinocommon plus other code.

However all rhinoscriptsyntax functions are coded using Rhinocommon so inspect.getsource() or the raw .py files are your best bet for getting from an identified functionality in rhinoscriptsyntax to the underlying methods in Rhinocommon

1 Like

Re: Grasshopper Panel – I simply meant the elements in the grasshopper menu.
XformRotation2 is one of the rs. methods one would use to write this functionality in python.
I am trying to do some matrix operations but I’ll need to learn more about the system before I can propose an approach.
Thanks

RE: inspect.getsource(), I will wait for a PC running 6 with the full editor. I am running a Mac with 5 and the editor is not the same as the one the PC guys enjoy.
Thanks

You can’t print ? Aiee that is a little limiting.

Do you have an ´out’ That you can connect a panel to, to see the print output ?

I can see output, but inspect.getsource() is not a command I am familiar with. Inspect doesn’t seem to be a keyword in python.

Rhinocommon is well documented for C# and VB and although it is not for rhino, its is pretty easy to figure out as it is a direct mapping. That is what was throwing me to use rhinoscript.

Thanks for your help! Things are going well now.

for closure, inspect is module that you need to import before you can call it. example:

import rhinoscriptsyntax as rs
import inspect

print inspect.getsource(rs.AddCircle)
1 Like

I recently tried this with the ghpythonlib.components module and found a standard identical helper function behind each GrassHopper component. I haven’t yet dug further down the stack to see whether there is useful Python code hidden in there somewhere…