Grasshopper

algorithmic modeling for Rhino


This is old code for baking objects with colors.  It still seems to work for surfaces and BReps, but doesn't work with curves and lines.  Any ideas?  Also, is there an easy way to add a way to specify the layer for baking?

Thanks.

---


  Private Sub RunScript(ByVal blnBake As Boolean, ByVal obj As OnBrep, ByVal color As Color, ByRef A As Object)

    If blnBake Then

      'Bake Object
      Dim mObj As New MRhinoBrepObject
      mObj = doc.AddBrepObject(obj)

      'Find obj attributes to change color
      Dim att As New MRhinoObjectAttributes(mObj.Attributes())
      att.SetColorSource(1)               'set color source to From Object
      Dim rColor As New OnColor (color)   'make OnColor
      att.m_color = rColor                'Set Object Color


      'Modify the attributes
      Dim objref As New MRhinoObjRef(mObj.Attributes.m_uuid)
      doc.ModifyObjectAttributes(objref, att)

    End If


  End Sub

Views: 333

Replies to This Discussion

The reason why it works for surfaces and Breps is because your asking Rhino to add a Brep object. Since surfaces are breps, it will work. However, since it doesn't consider a curve a Brep object, it won't add it.

As for controlling the layer, its not all that hard. Here's a quick example, but with no error checking. Add this line before you execute ModifyObjectAttributes
att.m_layer_index = doc.m_layer_table.FindLayer("myLayerName")
Yeah, I did see that and that makes sense. However, I had tried changing the request to MRhinoObject and doc.AddObject and unfortunately that haphazard guess did not do the trick. I really need to learn VB.NET instead of trying to hack together solutions or asking people to write code for me... :(

Marc

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service