Grasshopper

algorithmic modeling for Rhino

I am trying to create a .NET module that allows me to bake objects to specific layers. While the code below works if the layer doesn't exist, it will not set/change the current layer if it already exists. Does anyone know how to solve this?

PS the SetCurrentLayerIndex has no documentation so we're not sure we have correct arguments

If RhUtil.RhinoApp().ActiveDoc().m_layer_table.FindLayer(Layername) = -1 Then

Dim layer As New OnLayer()
layer.SetLayerName(layername)

RhUtil.RhinoApp().ActiveDoc().m_layer_table.SetCurrentLayerIndex(RhUtil.RhinoApp().ActiveDoc().
m_layer_table.AddLayer(Layer))

Else

RhUtil.RhinoApp().ActiveDoc().m_layer_table.SetCurrentLayerIndex(RhUtil.RhinoApp().
ActiveDoc().m_layer_table.FindLayer(Layername))

End If

Views: 1862

Replies to This Discussion

Hi Tody,
You are close. Here is how I would do it. Let me know if you need more help.

As far as I can tell the code that you've placed there works fine. I'm not sure if this is causing issues within a larger context or not, but that island of code seams good. The only thing I changed (which shouldn't be any issue at all) was the RhUtil.RhinoApp().ActiveDoc().... to the short hand of Doc. David has added a few "utility" members of which Doc is one of them and it references the currently active Rhino document. I'm not sure if that was the deal breaker, but at least it will clean up the code a bit.

Best,
Damien
The utility "Doc" and "RhUtil.RhinoApp().ActiveDoc().... " are exactly the same.
I agree that cleaning the code helps read and debug much easier. Also try to comment whenever you can and avoid using nested calls. Don't hesitate to declare variables and assign values to them.
Rajaa/Damien,

Thank you for taking the time to look at this. After cleaning the code (thanks for the tips) I discovered that it was a problem with the array of layers that I was feeding it. I had created a single panel with a list of layers separated by carriage returns as the input for the array. For some reason the array still worked if the layer didn't exist even though it was in a slightly wrong format (rogue spaces?).
Thanks again,

Toby

RSS

About

Translate

Search

Photos

  • Add Photos
  • View All

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service