Python: Display RH objects by layer in GH Python

Hi,
I have referencing Rhino Objects from the active rhino doc (with python) and I am not able to understand how to display them in GH. I am able to bake them back into Rhino. GH is also showing that I am properly referencing them.

I think this may have to do with setting the active document, but I am not sure. Attached is my Rhino File as well as my GH script which contains the python code.

I am interested in understanding how to do this with the Grasshopper.Kernel.GH_Convert.ObjRefToGeometry technique as well as a a method not using the GH API.

Thank you.

import Rhino
import scriptcontext as sc
import Grasshopper

rh_obj_list =
#rh_objs = sc.doc.Objects.FindByLayer(“ceilings”)
rh_objs = Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(“foo”)

for obj in rh_objs:
refobj = Rhino.DocObjects.ObjRef(obj)
goo = Grasshopper.Kernel.GH_Convert.ObjRefToGeometry(refobj)
rh_obj_list.append(goo)

sc.doc = Rhino.RhinoDoc.ActiveDoc

a = rh_obj_list

sc.doc = ghdoc

find_by_layer.gh (3.1 KB) find_by_layer.3dm (124.9 KB)

Is this what you’re looking for?

import Rhino
a = []
for obj in Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer("foo"):
    a.append(obj.Geometry)

findByLayer.gh (2.4 KB)

2 Likes

@Mahdiyar thank you this indeed works; however, I am not fully understanding the mechanics of what is happening behind the scenes. You have added the dot property ‘Geometry’ to the Rhino Object obj. Which namespace is ‘Geometry’ coming from? Is there a way to do this that is less short-hand?

Thank you for the help. Just trying to figure out how GH handles this conversion.

Rhino.DocObjects.RhinoObject.Geometry

1 Like

Thanks.

What I still don’t understand is why an ‘ExtrusionObject’ returned by the RhinoDoc FindByLayer operation doesn’t display in Grasshopper.

It seems David Rutten wrote Grasshopper.Kernel.GH_Convert.ObjRefToGeometry to convert Goo to GH.

Just trying to understand this process better.