Grasshopper

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

but it only returns color by object not layer color

Views: 1962

Replies to This Discussion

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.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service