Develop Python components that handle/modify Rhino Geometry (Breps in GH)

Hey guys,

over the past years I have always been working with “visual programming” by connecting existing components from the grasshopper menu and additional plugins. However, I would really like to start developing my own components. Currently my work always consists of hundreds of clusters and for me thats just too messy. Hence I would like to write smart components myself. I heard about rhino script syntax and rhino common but those are unknown territories for me.

Do you have an idea on how I could start writing my own components? Any good tutorials or documentations are appreciated.

Best

Max

Hi,

your best bet is this workshop by Long Nguyen, it will teach you all the basics you need for programming your own components.
I watched the first three parts and was pretty much ready to go (I have prior experience in arduino programming).
If you want to go deeper you will have to learn C#/Python basics.

Google is also your best friend when it comes to fixing bugs.

Also you might want to know that the Rhinocommon is just an interface between scripts and Rhino itself, therefore some rhinocommon functions might not behave the same way they do in Rhino.

For extremely advanced stuff you will have to learn Bezier/B-spline/NURBS theory.

Best regards
Tuyen

My suggestion would be:

RhinoCommon is a library accessible easily accessible from C#, Python, and VB.NET.

Grab a copy of MS Visual Studio Community edition (free to individuals, possibly not if you’re doing this directly for your company rather than learning a skill on your own time).

Spend a few hours trying out C#, VB.NET and Python. Run the hello world programs. Walk through a few tutorials with objects. During this period, basically ignore Rhino: you’re trying to see which of the three feels most natural to think in. For power, they’re all approximately equivalent. Until you get to a more advanced level, C# and VB.NET are basically functionally equivalent but just written in different styles and Python is a completely different thing.

You can really get inside of the geometry details with C++, but since you’re also apparently on your first text based programming language the learning curve would be much steeper: you want a problem like “Hmm, I tried to move a box and it disappeared; how do I fix that?” not “Rhino just disappeared and I have no idea why.”

C#/VB.NET have better integration into Microsoft’s development tools IMO, which might also be important if you want to write a tool that does something like bridging to Excel or Word. Python has an impressive set of libraries.

Don’t worry too much about your choice. For your first language “help, I’m drowning in punctuation!” (C#) or “wait, white space means something?” (Python) are perfectly valid reasons to pick something that minimizes the learning curve. That said, C# and Python seem to be most popular by a big margin in the discussion forums over VB.

Start browsing around https://developer.rhino3d.com/.

Download the Developer samples from McNeel. mcneel/rhino-developer-samples: Rhino and Grasshopper developer sample code (github.com). There are more resources one directory up. Those samples favor C#/VB.NET, but the online resources under developer.rhino3d.com are sometimes superior for Python. The guide to using Eto is an example (library so your UI will work on Windows and Mac).

The “your first plugin” type starter guides, also under developer.mcneel.com, are then great, whether or not your ultimate goal is to write a plugin: they and the developer samples will show you how to connect to Rhino.

From there, ask questions about things you don’t understand.

Thanks for your replies!
To give some more background information: I do have some experience in Python (I can develop Monte Carlo simulations). However, I also know that I want to develop components that are able to work with breps and surfaces etc. Most of my components will have to modify breps/surfaces into different shapes, store them on different layers etc. Let me show you a Cluster example that I created, which highlights the stuff I am doing. However, this cluster I need multiple times and its annoying. I rather iterate through one component and thats it. Which is why I want to get away from Clustering (less messy). I not only have this cluster I have many more… :smiley:
So I guess it might be more relevant for me to dive into C#?

Exposed_Floor_Roof.gh (32.1 KB)

If all you want to do is package a cluster into a component either basic Python or C# are sufficient, you just have to wrap your head around Rhinos Type conversion (Surface.ToBrep()) etc.

ah okey, if python is enough I will use that. Can it also bake to layers etc.?

Is there a documentation for Rhino Type conversions etc?

As Tuyen said, Python or C# should have pretty much the same power and will give you the next step through the same RhinoCommon calls.

For Rhino Type Conversions, I think the main resource is looking at the API docs:
developer.rhino3d.com → API → RhinoCommon.

Start with the RhinoObject and look at the types it can represent (ObjectType has an enumeration): Curves, Surfaces, ettc. Then Curve has subtypes like arcs and nurbs and polylines- surfaces are similar. Breps have a unique structure but it’s well documented.

I filed a documentation wishlist item to show the classes which inherit from a class; for now all the docs show is what class the one you’re browsing in help inherits from.

Hey Tuyen,
the workshops looks amazing. I think of watching it. Do you know if those C# components also work on mac? I want to write my own components that handle geometry. But they should ideally become proper plugins for grasshopper. I am only using Mac.

best
Max

I am not sure, I think there are some minor differences, never worked in Mac environments.