Rhino inside Python

@stevebaer Thanks, that looks very interesting!
But just to be sure: This is not a way to run Rhino Inside Python on Linux, is it?

Unfortunately not. Rhino is still running on the machine, albeit in a “headless” mode. Also, Rhino.Inside only works with Rhino for Windows.

Compute is currently the best option for interacting with Rhino from Python on Linux.

1 Like

Hello together,

this is my first time asking some questions in the forum=) I have been reading a lot here and always enjoyed the discussions and most of the times found solutions for me. I really appreciate and like the spirit here :ok_hand:

I hope this is the correct discussion for a problem I ran into:

My goal is to gather some information from a Rhinofile within a pythonscript with rhinoinside.

Similiar to what @guus.gooskens describes in his post.

Apperantly I am running into an issue when either using the RhinoDoc Methods:

  • Open()

  • Import() or

  • OpenHeadless()

      import rhinoinside
      rhinoinside.load('C:\Program Files\Rhino 7\System')
      import Rhino
      import os
      # current path
      path = os.path.dirname(__file__)
      # input file path
      inputFile = path + '\Test_Lines.3dm'
      # get the template file path
      templateFile = Rhino.ApplicationSettings.FileSettings.TemplateFile
      # create a new rhino document from the template
      rhinoDoc = Rhino.RhinoDoc.CreateHeadless(templateFile)

I always get this message back:

Process is terminated due to StackOverflowException.

I tested this with different Version of Python 2.7 and 3.7.

Am I missing something fundamental here?
Does anyone have a solution to this?

My workaround sofar is to use the File3dm class. Which seems to work.

Thank you :slightly_smiling_face:

Your code looks like it should work. There must be something in Rhino core that is causing this. I logged this in our bugtracking system and will try to see if I can repeat it.


Thank you for your response Steve Baer,

After reading your comment in your issue system I tried it with a blank installed version on my desktop with the same files, which worked flawless.
After that I checked all my installed plugins on my Laptop and blocked them from loading and it worked :grinning:
After trying enabeling the plugins one by one and testing it seems that V-Ray makes problems here.

Made a small function which does this for me so I dont have to do it manually in the Rhino settings.

def LoadPlugIn(id,Load):
   ''' disables or enables the plugin loading
       from the PlugIn id as a string 
       Load True or False '''
   # string to guid
   guid = System.Guid(id)
   PluginName = Rhino.PlugIns.PlugIn.GetPlugInInfo(guid).Name
   # get load status of the plugin
   LoadStatus = Rhino.PlugIns.PlugIn.GetLoadProtection(guid,False)[1]
   if LoadStatus != Load and LoadStatus == True:
       Rhino.PlugIns.PlugIn.SetLoadProtection(guid,Load)   # disable loading
       Rhino.PlugIns.PlugIn.SavePluginSettings(guid)       # save plugin settings
       if Rhino.PlugIns.PlugIn.GetLoadProtection(guid,False)[1] == Load:
           return (False,'Plugin {} stopped from loading'.format(PluginName))
           print ('ERROR: Not able to disable loading for {}'.format(PluginName))
           return None
   elif Load == True:
       Rhino.PlugIns.PlugIn.SetLoadProtection(guid,Load)   # enable loading
       Rhino.PlugIns.PlugIn.SavePluginSettings(guid)       # save plugin settings
       if Rhino.PlugIns.PlugIn.GetLoadProtection(guid,False)[1] == Load:
           return (True,'Plugin {} is loading'.format(PluginName))
           print ('ERROR: Not able to enable loading for {}'.format(PluginName))
           return None
       return (False,'Plugin {} already was stopped from loading'.format(PluginName))

Thank you :slightly_smiling_face:

Hi there, I am trying to use rhinoinside.load() but getting the following error:

Traceback (most recent call last):
File “c:\test.py”, line 10, in
File “C:\Program Files\Python39\lib\site-packages\rhinoinside-0.5.0-py3.9.egg\rhinoinside_init_.py”, line 34, in load
AttributeError: module ‘clr’ has no attribute ‘AddReference’

Here is the code I am using:
import rhinoinside
import rhino3dm
import Rhino
import Rhino.Geometry as rg

I am using Python version 3.9.5. Rhinoinside had to be installed manually after downloading from github. Pythonnet also had to be installed manually. I have also installed clr without which there were additional errors.

Any advice would be appreciated. Thank you!

Do you have Rhino 7 installed on this computer? This is a requirement for running Rhino.Inside

HI @stevebaer thanks for getting back to me. Yes I have Rhino 7 installed. I just uninstalled Python 3.9.5 and tried everything with Python 3.8.10, and it is working. It would be great to make it work with Python 3.9.5.

We need to wait until a 3.9 version of pythonnet exists. Is there a reason you need 3.9?

Our in-class demonstrations at IAAC in VS Code have been using Python 3.9. But if the current pythonnet version is not going to work then Python 3.8.10 it is :slight_smile:

For some reason Python 3.9.5 also required rhinoinside to be installed manually using python setup.py install and I was unable to use pip3.9 to install it.

Dear @stevebaer,

i am trying to use rhinoinside within vscode to run QuadRemesh method. How do i read a mesh from an external file (ply in this case).

here is the code that i am trying to use:

import rhinoinside
import Rhino
mesh = Rhino.Geometry.Mesh()
# mesh.Append(plyFilePath)
print(mesh.IsValid, mesh.ObjectType, mesh.Vertices.Count)
para = Rhino.Geometry.QuadRemeshParameters()
newMesh= mesh.QuadRemesh(para)

it prints
False 32 0

Thank you

Hi @stevebaer,
I only recently found out about rhinoinside CPython while working my way through the GH Hops tutorial. However currently I’m experiencing an issue while trying to load the modules with rhinoinside.load() with Python 3.8.10.
Could this be due to licensing issue? Currently I have Rhino 6 commercial license and Rhino 7 Evaluation (while waiting for my company to give RH7 :cry:)

Thank you for your time.

File ".\app-rhinside.py", line 3, in <module>
File "C:\Users\Anaconda3\envs\grasshopper\lib\site-packages\rhinoinside\__init__.py", line 41, in load
    __rhino_core = Rhino.Runtime.InProcess.RhinoCore()
System.Runtime.InteropServices.COMException: Error HRESULT E_FAIL has been returned from a call to a COM component.
   at Rhino.Runtime.InProcess.RhinoCore.InternalStartup(Int32 argc, String[] argv, StartupInfo& info, IntPtr hostWnd)
   at Rhino.Runtime.InProcess.RhinoCore..ctor(String[] args, WindowStyle windowStyle, IntPtr hostWnd)

Have you started Rhino 7 on its own? Also, do you have 3rd party plug-ins installed?

Other than a reminder License Expires in 6 Days on startup, the Rhino 7 Evaluation works normally for me at I don’t have any 3rd party plug-ins installed.

Oh, I wonder if that reminder dialog is the cause of the problem. I’ve been going through code and making sure that dialogs do not attempt to get displayed when running headless and this is one that I have probably not fixed.


I try the code in Ansys python editor and got this error.
The same error when use

rhinoinside.load("C:/Program Files/Rhino 7/System")

import rhinoinside
rhinoinside.load(r"C:/Program Files/Rhino 7/System")
System.IO.FileLoadException: The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
   at System.Reflection.AssemblyName.nInit(RuntimeAssembly& assembly, Boolean forIntrospection, Boolean raiseResolveEvent)
   at System.Reflection.AssemblyName..ctor(String assemblyName)
   at System.Reflection.Assembly.LoadWithPartialName(String partialName)
   at IronPython.Runtime.ClrModule.LoadAssemblyByPartialName(String name)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, String name)
   at IronPython.Runtime.ClrModule.AddReference(CodeContext context, Object[] references)
   at Microsoft.Scripting.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.LightLambda.Run4[T0,T1,T2,T3,TRet](T0 arg0, T1 arg1, T2 arg2, T3 arg3)
   at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)
   at Microsoft.Scripting.Interpreter.DynamicInstruction`4.Run(InterpretedFrame frame)
   at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)

I’m not surprised that isn’t working based on your previous comments that Ansys uses IronPython. Rhino.Inside python is specifically for cpython.

Ghpython isn’t Ironpython too?


All python that currently runs inside of Rhino uses ironpython as the interpreter. Your GhPython script sample should run exactly the same by removing the first two lines of your script.

Thanks for explanation but i still don’t understand why different error messages appears.
when i open Ghpython for the first time and with the same script it show me an error, in Ansys python also the error message changed

Without the code, is Ghpython load rhinoinside correctly because it is inside Rhino?