Grasshopper

algorithmic modeling for Rhino

Structures are valid outside their scripting component...sweet

This makes a lot of sense, but I never noticed before.  Apparently you can create a Structure in one scripting component and feed it to a downstream component with the type hint "system.object" and all of its methods will be available.  Of course there will be no tooltips (just like late binding a COM object), but it's still really useful.  (just imagine passing around multidimensional jagged arrays).  I thought I might share this as I think that it is awesome.

Cheers,

Ben

UpStream:
Private Sub RunScript(ByVal x As Object, ByVal y As Object, ByRef A As Object)
    Dim p As Persist = New persist("Fabulous")
    print(p.getS)
    A = p
End Sub

  Structure Persist
    Public m_s As String
    Sub New(ByVal s As String)
      Me.m_s = s
    End Sub
    Function getS() As String
      Return Me.m_s
    End Function
    Sub setS(ByVal s As String)
      Me.m_s = s
    End Sub
  End Structure

Downstream:
 Private Sub RunScript(ByVal p As System.Object, ByRef A As Object)
    print(p.getS)
  End Sub

Views: 303

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service