[GhPython] rs.ObjectsByLayer into Grasshopper geometry

How do I transform Rhino geometry into Grasshopper geometry.
Or Rhino UUIDs into Grasshopper UUIDs I don’t know.

This is what I try to do and I get NULL as output.

I believe the answer resides in Giulio’s answer here:

I still need to figure out if I can mass-transform objects without specifying their types explicitly.

you need to use rs.coercegeometry to return the geometry.
when you use rs.coercerhinoobject, you are returning the rhino “object”
https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_DocObjects_RhinoObject.htm
that object has properties, one of which is geometry.
https://developer.rhino3d.com/api/RhinoCommon/html/P_Rhino_DocObjects_RhinoObject_Geometry.htm

the straight rhinocommon approach might be something like this, (x being a string input with layername).

a = [obj.Geometry for obj in Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(x)]

Neither of these work:

rh_objs = [rs.coercegeometry(obj) for obj in rs.ObjectsByLayer(layer_name)]

rh_objs = [obj.Geometry for obj in Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(layer_name)]

I get NULL result but printing it I get the System.Guid object

You are not setting geos

1 Like

omg :man_facepalming:

this doesn’t work? (x input type hint set to string)

import Rhino
import rhinoscriptsyntax as rs
import scriptcontext as sc


# Rhino Common,don't need any scriptcontext stuff
#a = [obj.Geometry for obj in Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(x)]

# rhinoscriptsytax
sc.doc = Rhino.RhinoDoc.ActiveDoc
a = [rs.coercegeometry(obj) for obj in rs.ObjectsByLayer(x)] #returns list of objects
sc.doc = ghdoc

It does :smiley: I need glasses apparently :nerd_face:

When typing code that doesn’t do what one thought it would always first run the PEBCAK check (:

1 Like

:rofl:

I like this one: * PEBIAC (“problem exists between interface and chair”)

Yah well, I am old :°

for the past 3 months or so I was python-ing only in Rhino. Didn’t touch Grasshopper and I forgot to look for such details :smiley: