algorithmic modeling for Rhino
How to detect an object's display color when it's set to "ColorFromLayer"?
I'm looking at:
Private Sub RunScript(ByVal id As Guid, ByRef col As Object, ByRef by As Object)
Dim obj As Rhino.DocObjects.RhinoObject = doc.Objects.Find(id)
col = obj.Attributes.ObjectColor
By = obj.Attributes.ColorSource
Tags:
ObjectColor is the per-object colour. It's just not used when the ColorSource is not set to object.
You can use the DrawColor() method on the attributes to figure out what the actual colour in the viewport should be, but you'll need to provide it with the Rhino document (because if the source is layer, that function needs access to the document layer table).
Thanks David,
...and may I ask how to access the layer table?
Dim LInd = RhinoDoc.ActiveDoc.Objects.Find(id).Attributes.LayerIndex
is this what you mean for layer table?
An object stores an integer which refers to a specific layer in the layer table.
Once you have the index, you then need to look up the actual layer.
Something like:
Dim rhObject As RhinoObject = RhinoDocument.Objects.Find(id)
If (rhObject Is Nothing) Then Return
Dim idxLayer As Int32 = rhObject.Attributes.LayerIndex
Dim layer As Layer = RhinoDocument.Layers[idxLayer]
If (layer Is Nothing) Then Return
layer.Something
ps. It's better to use RhinoDocument instead of RhinoDoc.ActiveDoc because the latter is not multi-document safe. Grasshopper sets the RhinoDocument field before the script runs to the correct RhinoDoc.
Ok, I'm building lego with boxer gloves in the dark.
based on this comment i got:
Dim doc As Rhino.RhinoDoc = Rhino.RhinoDoc.ActiveDoc
Dim rhObject As RhinoObject = RhinoDocument.Objects.Find(id)
If (rhObject Is Nothing) Then Return
Dim DCol As Color = rhObject.Attributes.DrawColor(doc)
C = DCol
that seems to work :s
It will work fine on Rhino for Windows because it only ever has a single document (future versions may change in this respect). However Rhino for Mac is a multi-document program so the current document may no longer be the one associated with your script, if someone happens to switch.
Welcome to
Grasshopper
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
Added by Parametric House 0 Comments 0 Likes
© 2024 Created by Scott Davidson. Powered by