Grasshopper

algorithmic modeling for Rhino

Hi,

Can anyone suggest a convenient way of having a document static variable?

To date, I've used a singular master database that can easily be accessed from any component via a static variable handle.

I now wish to have a different database for each Grasshopper definition open.  I need somehow a handle based on which document the component is in to an "effective" static variable.

I'll explain further if the above is not clear.

Cheers,

Jon

Views: 385

Replies to This Discussion

Hi Jon,

do you really need this data to be on the document, or are you happy with it being in a database elsewhere? Every document has a DocumentID*, which you could use to associate tables in a database with a specific document.

It is not difficult for me to add some sort of UserData mechanism on GH_Document, I just want to understand if this is what is called for.

--
David Rutten
david@mcneel.com
Seattle, WA

* though looking at the code it seems it might often be 00000000-0000-0000-00000000
Actually the document ID would be a good reference.

I could use an event watcher to detect when the document changes, and either reference my global variable to the associated database from a library, or create a new one (if it doesn't exist).

I don't need to add UserData to the document, the database is created and maintained at runtime by the components.

It's still early in this particular plug-in that having a single database is fine for the time being, but if the doc id could be improved it would be useful. Is the docID assigned at runtime or embedded into the file? What happens if I duplicate a file external to Grasshopper and subsequently open both?

Thanks,

Jon
DocumentID is assigned randomly when a new document is created, but it is also stored in the file. So when a document is deserialized, it will most likely have two IDs (one upon construction, then changed upon Read()). There's no event for when the ID changes.

--
David Rutten
david@mcneel.com
Seattle, WA

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