Reference Rhino Layers Object GHPYTHON

Hi All, i wish to reference objects from a Rhino Layer. The layer may contain blocks, line and text

How do I break reference objects to the molecule level?

import rhinoscriptsyntax as rs

import scriptcontext as sc
import Rhino

sc.doc = Rhino.RhinoDoc.ActiveDoc
layer_name = x

box=
if run is True:
for obj in Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(x):
if rs.IsText(obj):
box.append(obj.Geometry.Text)
else:
box.append(obj.Geometry)
print(obj)

sc.doc = ghdoc

a=box

There are lot of ways.

Rhino 8 there are model objects. With Rhino 8 there are the new Grasshopper Datatypes. These are essentially Rhino.objects with a thin Grasshopper Wrapper around them. Here is the class for them:

They can be contain attributes and can be converted to a Rhino.Object if needed.

They can flow into other GH components too:


python_modelobject.gh (11.5 KB)
I apologize for the Python, for me it is a bit easier.

Code to walk into the ModelObject:

"""Grasshopper Script"""
xt=type(x)
xo=x.ObjectType
xl=x.Layer
xln=xl.Name


GHtype=xt
LayerName=xln
ObjectType=xo

And if you want to use them to get objects on a layer use Query document objects, then process them:


modelobjectlayer query.gh (10.4 KB)

"""Grasshopper Script"""

Layer = x.Layer

Hi Scott Davidson, I wish reference objects in Rhino by having input as layer name. I wish to do such using python?

Hi,
maybe a little overkill for your use-case but if you’re interested you could have a look at this source.

It “re-implements” something like GeometryPipeline but with the added functionality of creating pre-defined and timestamped layer-sets and being able to load & reference them on request, including event subscription and dynamic update in case the Rhino objects are modified.

It is a lot of code but (I think) has everything in there to adapt to your scenario:

Best wishes,
Max

I think this is how to grab stuff from the Layer. There is a thread about this here:

I wanted to test it against the ModelObject Components. You can see these Reference objects now travel with their attributes also:


sel_layer_to_gh_objs.gh (8.2 KB)

"""Grasshopper Script"""
import Rhino
import Grasshopper

rh_obj_list = []

rh_objs = Rhino.RhinoDoc.ActiveDoc.Objects.FindByLayer(x)

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

a = rh_obj_list