Rhino inside Python

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
rhinoinside.load()
import Rhino
mesh = Rhino.Geometry.Mesh()
# mesh.Append(plyFilePath)
print(mesh.IsValid, mesh.ObjectType, mesh.Vertices.Count)
para = Rhino.Geometry.QuadRemeshParameters()
para.TargetQuadCount=202
para.AdaptiveQuadCount=True
newMesh= mesh.QuadRemesh(para)
print(newMesh)

it prints
False 32 0
None

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>
    rhinoinside.load()
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.

2 Likes

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")
or
rhinoinside.load()

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?

image

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?

image

It’s probably a subtle bug in GhPython that an error isn’t always presented. Rhinoinside is specifically for cpython

1 Like

Hi @stevebaer
What is the role of rhino inside pyhton if we only need Visual studio to create rhino inside plugin?

Rhino.Inside CPython is specifically for loading and using Rhino inside of the CPython process. It could be used for all sorts of different applications including access to all of Rhino’s functionality from inside a CPython application like the ghhops-server.

1 Like

Thanks , but we can’t control it from Grasshopper like rhino inside revit?
I see this example but it need Rhino inside revit addon

https://www.rhino3d.com/inside/revit/beta/getting-started#ghpython-in-revit

No, for this we will need to be able to embed the CPython runtime in Rhino itself. This is a project that we are working on for Rhino 8.

3 Likes

Very nice , this will be useful and solve many problems with python modules.
I tried this and i will open separated topic to understand better how to send only one point.

image

I don’t know if this work or what i miss here

Hello @stevebaer
As you see i try this and it work fine without rhinoinside.
Now is it possible to send data from Grasshopper to Ansys directly?

In Ansys ironpython all Rhino commands available but there is a problem with some geometries, but actually it is not important because i only nee send and receive data.

Hi @stevebaer, I keep running into this. I have Rhino 7 installed and I think it fails to import Rhino.

PS C:\Users\user\Desktop\rhinoinsidepython> & C:/Users/user/AppData/Local/Programs/Python/Python37/python.exe c:/Users/userh/Desktop/rhinoinsidepython/rhinoinsideppython.py

Traceback (most recent call last):

File “c:/Users/user/Desktop/rhinoinsidepython/rhinoinsideppython.py”, line 2, in
rhinoinside.load()
File “C:\Users\user\AppData\Local\Programs\Python\Python37\lib\site-packages\rhinoinside_init_.py”, line 39, in load
clr.AddReference(“RhinoCommon”)
System.IO.FileNotFoundException: Unable to find assembly ‘RhinoCommon’.
at Python.Runtime.CLRModule.AddReference(String name)
PS C:\Users\user\Desktop\rhinoinsidepython>

Hi @stevebaer, any update on this? It fails to import ‘System’.

I just pushed a new version of rhinoinside for cpython to pypi. Try installing this version to see if if fixes the issue you are seeing