Grasshopper

algorithmic modeling for Rhino

Hi,

I need a little more info from the layerTable than the Human component gives (sort index and id), so I made my own.

But I need an auto update toggle as well and I don't understand a thing about events in VB. I don't need to keep track of what changed.

Can anyone help me out?

Views: 412

Replies to This Discussion

Generally if the object has no events which you can subscribe for, it's quite hard to keep track of changes. Anyway I think you should describe your problem a bit more precisely, can provide some code ?

Sure, my code so far :

  Private Sub RunScript(ByVal U As Boolean, ByVal AU As Boolean, ByRef Name As Object, ByRef Color As Object, ByRef Index As Object, ByRef Id As Object)

    If U Then

      Dim myLayerTable As Rhino.DocObjects.Tables.LayerTable
      myLayerTable = Doc.Layers


      Dim myColors  As New list(Of Object)()
      Dim myIndices  As New list(Of Object)()
      Dim myIds As New list(Of Object)()

      Dim i As Integer
      For i = 0 To (myLayerTable.Count - 1) Step 1
        Dim myLayer As Rhino.DocObjects.Layer
        myLayer = myLayerTable.item(i)

        myColors.add(myLayer.Color)
        myIndices.add(myLayer.SortIndex)
        myIds.add(myLayer.Id)
      Next

      Name = myLayerTable
      Color = myColors
      Index = myIndices
      Id = myIds

    End If

  End Sub

and what I need :

The way I understand it is that I need to expire this vb script component instance either when U is true, or when U is true and Rhino raises RhinoDoc.LayerTableEvent. I don't know how to catch that from inside my script component.

I don't know either how to expire it but I'll find out, there's plenty of discussions on that topic.

http://4.rhino3d.com/5/rhinocommon/html/E_Rhino_RhinoDoc_LayerTable...

This is the event we're talking about I guess.

Consider the following code a sketch, it won't work probably the way it's written... but it gives you the idea. I'm not sure if the MyLayerHandles sub should be shared, as the LayerTableEvent is shared (those shared <> non shared relationships are always tricky to me). 

 

AddHandler RhinoDoc.LayerTableEvent, AddressOf MyLayerHandler

RemoveHandler RhinoDoc.LayerTableEvent, AddressOf MyLayerHandler

Sub MyLayerHandler(sender as object, e as LayerTableEventArgs)

     'here you can do something to react to layer changes

     'also has actually some informations about what exactly happened

End Sub

Thanks Mateusz! The examples on msdn etc are always a bit too abstract, this will clutch.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service