Grasshopper

algorithmic modeling for Rhino

Does anyone know how to add a persitant tag (string parameter) as an attribute or other property that can ibe instantiated once a custom gh component has been instantiead for the first time by the user?

I want this tag to be written somewhere as a persitent attribute to the component that can be re-read once the user saves a GH document and reopens it.

 

Basically this tag would tell teh user what instatiation number the component is on the canvas,

 

cheers

Views: 365

Replies to This Discussion

Hi Steve,

can you please elaborate what you mean by "attribute", "property", "tag" and "persistent"?

--

David Rutten

david@mcneel.com

Poprad, Slovakia

I want my user to assign a nameID to my component. This is taken as a string input parameter. I want this name to be then be stored as a permanent variable by my custom component say - strOriginalComponentNameID.

 

When grasshopper is saved, the document closed, and the docuemnt reopened, I want the component to have stored this variable internally as a persistent data variable.

 

I know I can do this be changing the nickname variable of the component. This is updated, saved and restored when a document is closed and reopened. However, I dont want my component to allow  user to chnage the Nickname. Right now though this is the only way i can think of doing this,

 

 

Steve

Ok, I think I understand. You want to have private variables on your component that are (de)serialized, right?

To do this, you'll need to override the Write() and Read() methods:

Public Overrides Function Write(ByVal writer As GH_IWriter) As Boolean
  writer.SetString("CustomNameID", m_customNameId)

  Return MyBase.Write(writer)
End Function


Public Overrides Function Read(ByVal reader As GH_IReader) As Boolean
  m_customNameId = Nothing
  reader.TryGetString("CustomNameID", m_customNameId)

  Return MyBase.Read(reader)
End Function

--

David Rutten

david@mcneel.com

Poprad, Slovakia

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