Automate grasshopper from rhino plugin

i’m searching for an example code to automate grasshopper from a rhino plugin.
I want automatically load a grasshopper file, assign data and bake some objects.

Hi dsw,

there are some functions, which are exposed via the plug-in COM scripting object.
A list is here, but you can also use the GrasshopperGetSDKDocumentation command (or entry in the Grasshopper menu, under Help) to get the full docs on your disc. Please note, that this list might still change a bit over time.
The interface is located in Grasshopper.Plugin.GH_RhinoScriptInterface.

You can add a question on the Grasshopper forum if you need more help, too.
I hope this is helpful,


Giulio Piacentino
for Robert McNeel & Associates

Thanks for the answer. But i have not a problem using the grasshopper SDK, i don’t know how i can do the following in C++:

Option Explicit

Call Main()

Sub Main()

  Dim GH : Set GH = Rhino.GetPluginObject("Grasshopper")


  Set GH = Nothing

End Sub

Now I’ve looked for a sample about consuming that type of interface from C++, but could not find one. Maybe @dale knows about one.


Giulio Piacentino
for Robert McNeel & Associates

Using COM/ActiveX automation in C++ is not for the faint of heart. But is is possible to get Grasshopper’s IDispatch object and invoke methods on it. What is available to invoke on the object is listed here:

To get Grasshopper’s object, use CRhinoApp::GetPlugInObjectInterface and pass it the UUID of Grasshopper - which you can get from Rhino’s plug-in manager (Tools -> Options -> Plug-ins). CRhinoApp::GetPlugInObjectInterface returns a pointer to a IUnknown object. But you should be able to cast it as an IDispatch pointer.

Once you have this, you can find the DISPID of the OpenDocument using IDispatch::GetIDsOfNames, and then invoke the method using IDispatch::Invoke.

There is a lot of info on C++ COM/ActiveX on MSDN - work doing some reading.

Here is a sample that you can review:

i think a better way is to use the #import directive in C++ to create interface classes. for this i need the typelib of the grasshopper. to create this i must use regasm.exe to extract the tlb out of the dll. but at this point i get a error message, that the RhinoCommon.dll 5.1.30000.4 is missing.

now only david can help with providing either the tlb or the right rhinocommon.dll…

The RhinoCommon.DLL is going to change version numbers with each service release of Rhino. I would stick with Dale’s approach.

If you look at the interface (reference by Giulio), most methods don’t require a parameter. And those that do only require simple parameters. So not really “better”, just “different.”

Yes, you are right, it’s a different approach. But in my point of view it’s a more readable and more exact approach, which i want to use.
So are you able to send me the RhinoCommon.dll 5.1.30000.4?

I’m confused. Why do you want an older RhinoCommon? I doubt an older RhinoCommon will work with a newer service release. Even if you were going to generate a type library, you’d need to generate one from Grasshopper, not RhinoCommon. And, Grasshopper is dependent on Rhino. So using regasm is pretty useless as you cannot create a Grasshopper COM object outside of Rhino…

That’s what i try to do. I just need the typelib to generate a C++ class. I do not use it to run rhino nor grasshopper!

Who said i want to make a Grasshopper COM object outside Rhino? I want to use RhinoApp().GetPlugInObjectInterface(…) to get the IDispatch from Rhino and i want to invoke the methods from this interface.

My only suggestion for you is to try to use Tlbexp.exe to create a type library from either GrasshopperPlugin.rhp or Grasshopper.dll (I am not sure what assembly the COM interface resides in). Once you have a type library, you can use regtlibv12.exe to register it.

If you need more help, you might need to post on the Grasshopper community site do the developer can chime in.

I’m currently stuck assigning data to a parameter in grasshopper. The second parameter of AssignDataToParameter is an object and i don’t know how to assign even an integer to a parameter.

Can you give me an example how to assign a number and a rhino-object (for example a surface)?


If you working with COM in C++, then you are going to have to pass data a a VARIANT. If the data is more than just simple data, then your VARIANT will need to contain a SAFEARRAY of data or perhaps VARIANTs.

I can’t open your link:“Here is a sample that you can review:

Can you send me one?Any replies would be appreciated.

Thank you very much!Thanks