Python - loading and linking geometry from rhino to grasshopper

Hi All,

I’m trying to write a component similar to the geometry pipeline in grasshopper. Basically, I want to load objects from certain layers to grasshopper and filter those that are inside the polygon. I’m able to input and filter the geometry I need, but the problem is that my output in grasshopper is not linked to rhino geometry. When I’m moving a curve, it’s not being moved in grasshopper.


What was loaded “stays” in place even though its position changed. What I would like to achieve is something similar to right clicking on the curve component and selecting “select one curve” - in this case when I move the selected curve, the change is reflected in grasshopper.

Could someone help me with this? Also when I change my polygon input whole node highlights red and shows error: “1. Solution exception:Object reference not set to an instance of an object.”. (When I try to move some control points).

And last but not least is my approach correct? At the end of the day I wanted to load to grasshopper geometry that is only within a specific area. Could it be that using geometry pipeline would be more efficient - I have a lot of curves? Or coding it by myself is the right approach?
geometry_pipeline_example.3dm (34.5 KB)
input_selection_example.gh (9.7 KB)

I think even if you have uuids of the Rhino objects in the first place, you’re not storing them in your filter function, you’re just adding a curve instance from those to ghdoc.Objects. This is not the original Rhino object.

In your code, there’s a mix between a curve objs coerced from an obj_id originally from sc.doc =Rhino.RhinoDoc.ActiveDoc in OnTextMenuClick, which are then if filtered, directly appending to the ghdoc.Objects. I don’t quite understand what you’re trying to achieve in Grasshopper, to change Rhino objects without baking the Grasshopper objects back into Rhino, so I can’t say it’s impossible. But in my experience mixing Rhino.RhinoDoc.ActiveDoc with ghdoc is highly troublesome, and I’ve never managed to get anything to work as expected that way in code. Leave it to the native params and normal non-Python workflow.

I recommend distinguishing between a) real Rhino uuids, e.g. from rs.ObjectsByLayer with sc.doc = Rhino.RhinoDoc.ActiveDoc, b) references to a Rhino obj in grasshopper (e.g. from a Geom param, right clicking select Multiple Objects - these can be identified as their uuids’re recomputed with each solution), and c) geometry embedded in Grasshopper (e.g. stored in a Geom param that had references to Rhino Geometry, via right clicking and internalise data). This persists even if a new Rhino document is opened (closing the previous one).

1 Like

Thanks a lot for your answer James, it was really helpful. Finally I decided to use geometry pipeline component.

1 Like

I didn’t look at your code, but this GHPython dynamic layer reader might help if you still want to try coding things:

2 Likes

This is what I was looking for, thanks a lot @AndersDeleuran!

1 Like