Grasshopper

algorithmic modeling for Rhino

Hi,
What is the function to turn layers off in the current Rhino document?

I can get a the count of all layers but how do i set a layer current and turn its visibility off. I'm am trying to do a animation and bake objects to sequentially different layers but want the previously baked layers to be off.

Dim LayerTable as MRhinoLayerTable
LayerTable = doc.m_Layer_Table

for i as int32 = 1 to LayerTable.LayerCount
Dim Layer as new onlayer
layer.SetLayerIndex(i)
Layer.Setvisible(False)
next i

Any suggestions?

Views: 1721

Replies to This Discussion

I think you're almost there. The last thing you should need to do is then go back and modify the layer in question... LayerTable.ModifyLayer (layer, i, true)

Two things here. First off, rather than declaring Layer as a new layer, I would retrieve the layer directly from the layer table. That way it would have all of the other attributes for the original layer. Secondly, if you're baking each frame to a layer, your file is going to get very big very quick. I'm not sure what's the best way to really go about getting around this other than not baking to layers. Maybe saving after each iteration might be worth while. HTH
Thanks for the tips. Unfortunately, I am still not getting this to work.

I'm not familiar with native Rhino Script so is the final syntax below what you would use?

Dim LayerTable As MRhinoLayerTable
LayerTable = doc.m_layer_table

For i As int32 = 1 To LayerTable.LayerCount

Dim layer As New OnLayer
Layer.SetLayerIndex(i)
Layer.SetVisible(False)
layertable.ModifyLayer(layer, i, True)

Next i

I also seem to be having an issue with GH updating its layer table. I enclose here a screen shot of actual layers in the Rhino file and the layer list in GH. There seems to be a disconnect here.

Any ideas?
Attachments:
Ultimately, an OnLayer and an MRhinoLayer are not the same thing, although they share certain attributes. Within your code, it looks as though you're simply replacing layers which don't really have anything to really do with the layers that they are looking to replace. Ideally you'd retrieve the layer from the layer table, do what you need to do with it, then modifiy that layer with the adjusted copy. The "odd" thing here is that you can't really modify an MRhinoLayer, you need to make the modifications on a OnLayer. Its not in the documentation (which stumped me for a little while), but you can create a new OnLayer from an MRhino layer and that's what you'll want to do in this case. The code below should do what you're looking for.


Dim LayerTable As MRhinoLayerTable
LayerTable = doc.m_layer_table

For i As int32 = 0 To LayerTable.LayerCount -1

Dim layer As New OnLayer(LayerTable(i))
Layer.SetVisible(False)
layertable.ModifyLayer(layer, i, True)

Next

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service