Rhino inside Python

is it possible to use rhinoinside inside rhino or only outside of rhino.
So i can only use cpython modules outside of rhino but not inside with the grasshopper python editor ?.

I mean if i use your example it works but can this rhino.curve.object be exist in rhino to make it visible?

sorry i am very new to this

Hi, Flokart. I think that what you are trying to achieve is not a rhino inside subprocess. If what you want to do is run a CPython script inside Grasshopper, maybe you can succeed with this plugin:

or this one:

@flokart It’s not currently possible to use cpython modules in Rhino/Grasshopper because it uses IronPython (not withstanding the workarounds that @ffribeiro shared). If you run Rhino.Inside CPython then you don’t get the Rhino UI, but all the geometry you create can be written to a 3dm file and viewed in regular Rhino.

Really neat project!
One thing that I’ve been struggling with is using methods from RhinoApp.
For example I’ve tried to use Rhino.RhinoApp.WriteLine("Hello World"), but nothing seems to show up.

However, if I use print(Rhino.RhinoApp.Version) in python I get the expected version: 7.0.20007.12535. Is there something I’m missing to control Rhino from python?

This command writes to the Rhino GUI command-line, not to terminal. Since Rhino inside Pythen runs headless you won’t see anything.

Great news, looking forward on testing this @stevebaer, thanks!

Hi @nathanletwory, perhaps it is a good idea that there is some kind of output redirection, don’t you think? WriteLine and Print are used quite often for debugging. I had to use chrome in headless mode recently and without being able to print something on the terminal I wouldn’t be able to fix my bugs.

Nothing is stopping you from using print that comes with Python…

1 Like

Sorry if this is obvious: So rhinoinside only connects to a headless Rhino?

I very much love the UI of Rhino and all of its functionality, but I also write Python 3 (not iron python friendly) code. Is it possible for rhinoinside to connect to an existing Rhino instance, and interact with the active document?

For the method of using Rhino that I described above this is correct as python is a headless console application controlling and containing Rhino.

This may eventually be possible, but I haven’t figured out how to do this yet.

1 Like

Thanks for your reply, I wonder if other people also have similar needs. At the moment the GH_CPython libraryis not very robust.

Hope you figure this out soon. :muscle:

1 Like

You aren’t alone, many people want python 3 support and many others want CPython support. We know this is an issue, and the technique described in this post is all we can offer for now.

4 Likes

Guys, thank you for your comments, I was very interested in reading them.

really want rhino gui

Hello guys!
First of all, thank you very much for this great implementation!
Im running some tests here to see what I can do, but found myself stuck right now. In this test, Im trying to use the method Curve.ClosestPoint(Point) from Curves class,
but for some reason unkown to me, it does not work.

If I try basically the same code inside Rhino, it works just fine.

Any idea why?

Thanks.

The signature is bool ClosestPoint(Point3d p, out double t). I think the way to call this is:

rc, t = curve.ClosestPoint(pt.Location, 0.0)

where rc will be the return value of the method and t the out value.

1 Like

Thank very much!
I see, I get it now. So I have to set a return variable and an out value.

Hello there,

First, thanks for the implementation, would you recommend it for production yet ?

Secondly, I’m trying out to use rhinoinside and I’m running into some problems using the API.
I’m trying to use NurbsSurface.CreateNetworkSurface, and I always get

typeError: No method matches given arguments for CreateNetworkSurface

Here is the way I call it :

top_u_curves = Rhino.Collections.CurveList([curve_uf,curve_ub])
top_v_curves = Rhino.Collections.CurveList([line_u_start, line_center_up_pont, line_center_up_middle, line_center_up_tenon,line_u_end])

tolerance = 0.01

surface, error= Rhino.Geometry.NurbsSurface.CreateNetworkSurface(top_u_curves,2,2,top_v_curves,2,2,tolerance,tolerance,tolerance,0)

I’ve tried using regular python lists and System.Collections.Generic.List[Rhino.Geometry.Curve] instead of Rhino.Collections.CurveList.
I’ve tried removing the last argument, I’ve failed to use the clr.Referencein method…
I can’t figure out if my problem is with the types (double vs float, list of some sort) or with the out argument value …
Neither linter nor autocompletion is useful in this case and I can’t find examples on the web, do you have an idea ?

I’ve seen posts in the documentation about this topic but it references IronPython which I’m not sure I’m using since I’m running Python 3.x version and I recall that IronPython is only available for Python 2.x correct ?

Hello, can you try without the final zero in the method call?
Graham

Hello Graham, as said in the post I already tried removing the last argument (0) and sadly I get the same result :

TypeError: No method matches given arguments for CreateNetworkSurface: (<class ‘Rhino.Collections.CurveList’>, <class ‘int’>, <class ‘int’>, <class ‘Rhino.Collections.CurveList’>, <class ‘int’>, <class ‘int’>, <class ‘float’>, <class ‘float’>, <class ‘float’>)