jia.yeap
(Jia Yeap)
May 17, 2024, 1:35am
1
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
scottd
(Scott Davidson)
May 17, 2024, 2:17am
2
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
jia.yeap
(Jia Yeap)
May 17, 2024, 4:55am
3
Hi Scott Davidson, I wish reference objects in Rhino by having input as layer name. I wish to do such using python?
efestwin
(Max Eschenbach)
May 17, 2024, 5:49am
4
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:
"""
Provides an interface to work with interactive geometry pipelines.
Inputs:
DynamicUpdate: If True, the component will listen to changes in the Rhino document and update automatically. {item, boolean}
CreateAndRef: Set to true to create new timestamped pipeline-layers and reference them. {item, boolean}
LoadAndRef: Set to true to load existing pipeline-layers based on the currently active Rhino layer. {item, boolean}
ParentLayerPrefix: The prefix for parent pipeline-layers {item, string}
ReferenceLayers: Specify the referenced layer names here (i.e. connect a panel). {list, string}
AssistanceLayers: Specify additional non-referenced assistance layers here (i.e. connect a panel). {list, string}
LayerColours: Use this to specify a color for the layers that are created by the component. {list, string}
Outputs:
AssemblyGeo: The geometry in a datatree branched based on the specified layers. {tree, geometry}
CurrentLayers: The currently referenced layers as strings. {list, string}
Remarks:
Author: Max Eschenbach
License: MIT License
Version: 200705
"""
# PYTHON STANDARD LIBRARY IMPORTS
This file has been truncated. show original
Best wishes,
Max
scottd
(Scott Davidson)
May 17, 2024, 3:35pm
5
I think this is how to grab stuff from the Layer. There is a thread about this here:
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.ObjRefToGeometr…
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