Grasshopper

algorithmic modeling for Rhino

Hello,

In my GH definition, i have many VB components using the same VB structure type :

  Public Structure CritereNDC
    Public txtNo As String
    Public txtTitre As String
    Public txtVerif As String
  End Structure

Those VB components are not all linked to each others. So i repeat in each of them this same declaration.

Is it possible to put this structure declaration only one time in my GH definition ?

Thank you for reading,

Jean-Louis

Views: 336

Replies to This Discussion

Not at the moment. If you want to do this you have three options:

  1. Stop using individual VB Script component and instead switch to Visual Studio and make a GHA. Then all your components can share all the classes and structures and interfaces you want.
  2. Make a dll which contains all the shared types using Visual Studio and import it in all your script components.
  3. Make your structure (de)serializable to -say- a string. Then you can pass the strings back and forth and (de)serialize them whenever needed. You'll still need to copy paste the structure code into every script component, so it's not great practice, but it'll allow you to share data between disjoint components.

Thank you David. In the 3rd option, how can i use serialization ability in a GH definition ?

Do you mean global variables could be possible in a further GH version ?

JL.

I'd like to add shareable code blocks to GH2 to make this easier. But none of that is working yet.

As for serialization, you should override the ToString method on the struct to return a full description if the data, and add a constructor which takes a string and reinstates the relevant fields.

Another option entirely (number 4) is to use tuples or dictionaries, since these are framework types they are available to all code.

RSS

About

Translate

Search

Videos

  • Add Videos
  • View All

© 2024   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service