[GhPython] rs.ObjectsByLayer into Grasshopper geometry

(IVELIN PEYCHEV) #1

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.

0 Likes

(IVELIN PEYCHEV) #2

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.

0 Likes

(Chris Hanley) #3

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)]
0 Likes

(IVELIN PEYCHEV) #4

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

0 Likes

(jesterKing) #5

You are not setting geos

1 Like

(IVELIN PEYCHEV) #6

omg :man_facepalming:

0 Likes

(Chris Hanley) #7

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
0 Likes

(IVELIN PEYCHEV) #8

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

0 Likes

(jesterKing) #9

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

1 Like

(IVELIN PEYCHEV) #10

:rofl:

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

0 Likes

(jesterKing) #11

Yah well, I am old :°

0 Likes

(IVELIN PEYCHEV) #12

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:

0 Likes