Rhino inside Python

This is probably a Python.NET issue as that is the library being used in this case for interop between CPython and .NET. I’ve found the library to be pretty finicky for some cases and this may be one of them. @eirannejad has been playing with Python.NET lately and may have a better idea of what to try.

1 Like

Any news on the subject ? Is there a way to contact support for a faster discussion ?
My company is thinking of using rhino inside for a new project and we need to certify that everything we want is possible with this tool first.

Thanks for your answers.

I’m looking into this now and will let you know if I can figure anything out.

[edit] based on a quick search of stack overflow, I found this topic

You may have to create a “dummy” variable to pass in for the last out parameter. Something like

import rhinoinside
import System
import Rhino

dummy_out = System.Int32(0)
surface, error= Rhino.Geometry.NurbsSurface.CreateNetworkSurface(top_u_curves,2,2,top_v_curves,2,2,tolerance,tolerance,tolerance,dummy_out)
1 Like

It did the trick !
Now this method call goes through and at least it returns an error code but it’s my part to solve :slight_smile:
Thanks a lot for the help


Hey there, I’m back for more questions ^^

  1. Is there as way to execute a grasshopper script directly from rhinoinside (or at least in a headless way) ?

See I’ve been trying to make my rhino/gh use headless to embed it within a python app, I’m in the process of transcripting my GH scenarios in python with rhino inside library but I found the process to be complicated since there is no direct equivalent in RhinoCommon to the grasshopper components that I use.

  1. The best way would be to be able to call something like execute_script with my GH script but if it is not possible, is there a place to look for operations under the hood of GH components ? For example, if I want to mimic the behaviour of the Patch geometry GH component I’d like to know which RhinoCommon method of Patch is used and with which parameters. Or maybe there is a Grasshopper inside hidden library somewhere ? ^^

Thanks for your time

Hello Thomas,

you can check out my post concering your first question:

Right now it does not work for python components, so I am currently using Rhino.Compute.

1 Like

I’ve been trying to get headless grasshopper to work from cpython using rhinoinside as well. I’ve had some success working through all of the examples I can find in jupyter notebook, but ran into the same roadblock you did, Martin. I’ve only been able to get vanilla components and the C# scripting component to work, and not the ghpython components or some of the common plugins similar to your experience. I was ambitiously hoping to be able to use it to batch process diva simulations of models among other things.

For the time being I’ll probably end up setting something directly within ironpython in a Rhino instance for now, but it would be great to continue with Rhinoinside+headless grasshopper once a way through that limitation was more clear.

1 Like


I’m having problems trying to serialise data using Rhino.FIleIO with rhino inside python.

I have succesfully created some meshes and saved them in a 3dm file, all good there. Now I’d like to export the same meshes to an obj file.

  1. the Rhino.FileIO.FileObj.Write requires a RhinoDoc object, how to get the RhinoDoc corresponding to my data ? I managed to get one by opening the saved 3dm file containing my data but I’m guessing it’s not the optimal way…

  2. when I use the Rhino.FileIO.FileObj.Write function I get a pop up asking for mesh precision, all good there but when I accept the pop up I get an error :

    System.Reflection.TargetInvocationException: Une exception a été levée par la cible d’un appel. —> System.AccessViolationException: Tentative de lecture ou d’écriture de mémoire protégée. Cela indique souvent qu’une autre mémoire est endommagée.

   à UnsafeNativeMethods.RHC_RhinoMeshObjectsWithTransform(IntPtr pArrayConstCRhinoObject, Int32& uiStyle, Transform& xform, IntPtr pMeshParameters, IntPtr pArrayMeshes, IntPtr pArrayAttributes)
   à Rhino.DocObjects.RhinoObject.MeshObjects(IEnumerable`1 rhinoObjects, MeshingParameters& parameters, Int32& uiStyle, Transform xform, Mesh[]& meshes, ObjectAttributes[]& attributes)
   à Rhino.FileIO.FileObjWriter.GetMeshObjects(FileObjWriteOptions options, List`1 rhinoObjects, MeshingParameters& parameters, Int32& uiStyle, Transform xform, Mesh[]& meshes, ObjectAttributes[]& attributes)
   à Rhino.FileIO.FileObjWriter.WriteMeshesToFile(List`1 rhinoObjects, FileObjWriteOptions options)
   à Rhino.FileIO.FileObjWriter.WriteFile(StreamWriter file, RhinoDoc doc, FileObjWriteOptions options)

Could someone enlighten me about this kind of error ? I tried giving admin rights to my python editor but it is not sufficient… Is this problem coming from export obj functions within rhinoinside ?

Also 3) Can you confirm that there is no way to get a 3D preview of the data directly from rhinoinside ?

Thanks for your help,

If you have a script I can run to repeat this, I can run it in a debugger to try and figure out what is happening

Hello Steve,

Thanks for your time, here is my code sample zipped with the virtual env used and the read 3dm file.
Here I only test opening a doc from the 3dm file and trying to export it in obj.
I don’t know why it fails and I don’t know how to get the doc from a 3dmfile python object instead of having to write it and opening it.test-export_obj.rar (8.1 MB)
Of course to be able to run it you need to change the paths at the top of the python file.

Why are you trying to run rhinoinside inside Rhino? It is intended to be used outside of Rhino.

On your command-line of your first screenshot run python, then execute the four lines you have in the second screenshot.

Nathan is correct. What is it that you are trying to do?

Thanks Nathan, my question is really stupid, I now know that Rhinocommon is called in python.