Mixing GhPython and C#


(Andrew Carmichael) #1

Hi there,

So I’m pretty much brand new to GH scripting and to be honest, am not an amazing programmer in the first place. Buuuuut just got started on designing a plugin.

Initially I wen’t for doing so with GhPython as it’s a pretty friendly language and the facilities for it withing GH make it pretty straightforward.

However, I’ve noticed that there are a few things that I want to do (such as have the input term be a drop-down box) that appear to only be available if I use C# or VB.

So my question is, is there any facility to combine both languages? or convert the python to c#?
Is it the case that for simple scripting it’s easier to use Python but for fancier stuff I’m better off with C#?


(Giulio Piacentino) #2

Some of these things are also possible in GhPython for Rhino 6, but if you want to heavily change the UI, then doing so is easier in C#, as there are more examples and the API itself is written in a strongly-typed language, with all the pros and cons.

I think the difference is really if you want to change Grasshopper, or if you want to give value to your users by actually providing geometrical operations. There are no issues in using Python for geometry, but if you are required to change the Grasshopper UI heavily, then the Grasshopper SDK is best consumed from a strongly-typed language.

If you are writing it in two different components, they can easily collaborate. Maybe writing some stuff in Python and the UI logic in C# is a good mix.

Otherwise, it’s possible but not extremely easy to mix in the same component. After all, the GhPython component is written in C# – but I wouldn’t go down that path. If really required, the easiest is (1) to consume C# assemblies from Python, but then it would mean to ship a separate .dll with the definition. Other options are (2) interpret Python from C#, but it becomes difficult to debug and edit; and (3) compile C# from Python, but it’s really not that ideal IMO.

There isn’t such a tool. The main issue is that rhinoscriptsyntax is a procedural library that does not exist in RhinoCommon/C#.

(Andrew Carmichael) #5

Thanks Giulio, that’s a really useful description. I think in my mind i’m actually trying to design an interface how it would look on a normal panel in any program as opposed to using multiple components in succession as is common in GH. But maybe with Tip Hints and simplifying things a bit I can just sort it out with multiple componets (for version 1.0 anyway) then add more complexity later on as I gain more understanding.

Appreciate the help!