Grasshopper

algorithmic modeling for Rhino

I am trying to write some code that takes in a string and checks to see if the layer 
exist and if it does exist makes sure that it is visible. I also want to check if a different 
string(say Green3) is the name of an existing layer and if so figures out the suffix 3 
and creates a new layer Green4.

In order to do this I have been reading up on the sample pages and the Rhinocommon 
SDK but I seem to be not grasping how to access certain members. I have written 
below how I think I would access the members. Can someone please explain why my 
logic is incorrect. I have a feeling I am not grasping the Structure of the classes.


This is the sample code from the LayerTables find method page in the RhinocommonSDK
 

Public Shared Function AddLayer(ByVal doc As Rhino.RhinoDoc) As Rhino.Commands.Result 


'Does a layer with the same name already exist? 

Dim layer_index As Integer = doc.Layers.Find(layer_name, True)


Since the find method is part of the LayerTables class which is part of the 
Rhino.DocObjects.Tables namespace I would have thought the above would have been 
Rhino.DocObjects.Tables.LayerTables.Find(layer_name,True)

thanks.

Views: 348

Replies to This Discussion

So I made some progress on understanding Layers but still don't understand why this doesn't work(layer is a string parameter that is passed into the VB component)

    Dim layer_index As Integer = doc.Layers.Find(layer, True)
    Dim temp As Rhino.DocObjects.Layer
    temp = doc.Layers(layer_index)
    temp.IsVisible = True

Any ideas? I know this is probably something really easy. Thanks.

I can't get it to work either. Strange.

Still looking.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Ah! you need to call CommitChanges() on your layer when you're done modifying it. Very undiscoverable.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks David. Is info like this documented anywhere? I would have never guessed this and  I just spent a few hours looking on the web and racking my brain. At least I know I wasn't being too dense.

It should have been documented on the IsVisible etc. properties themselves. I'll add the comments after I confer with Steve so I fully understand why it needs to be this way.

--

David Rutten

david@mcneel.com

Poprad, Slovakia

Thanks again - I appreciate you taking the time to take a look.

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