Grasshopper

algorithmic modeling for Rhino

I've starting developing custom GHA components and I'd like to better understand how Grasshopper definitions using custom components are saved to GHX files and then opened later.

 

1) If a GHX file saved with custom components is opened on a computer with out those custom components avalible what will happen? Will Grasshopper only load the components in the document it understand or will opening the document just fail?

 

2) What if a GHX file saved with custom components is opened on a computer with a newer or older version of those custom components? Does the GHX file just save a reference to the full name of the GH_Component class, regardless of the version currently loaded. Or does it restrict itself to a specific version of the custom component assembly?

 

3) How can I save and later restore extra information related to the state of a custom component to and from a GHX file?

 

Views: 1689

Replies to This Discussion

Hi Eric,

 

1) components need to be loaded for them to deserialize from a ghx archive. If they are not loaded they will be skipped and a warning message will be displayed at the end of the loading process informing the user the network is incomplete.

 

I've been thinking for a while about reading in these blobs of incomprehensible data in an attempt to maintain them through an open/save cycle, but I'll never be able to get this process watertight.

 

2) When you release components, you should try and make sure that they are backwards compatible previous releases. For example, if you decide to change the number of inputs/outputs or the type of inputs/outputs, this might well break file IO. What you should do in those cases is:

 

- Copy-paste the old component source code and change the ComponentGuid property. In essence, you make a different component which will have the changes.

 

- Change the Exposure property on the old component to be GH_Exposure.hidden. This will hide the component from the interface.

 

This basically means that when people open a file that uses the old style component, they'll get the old-style component. If people instantiate the component anew, they'll get the new component.

 

Grasshopper and it's default gha assemblies feature dozens upon dozens of these hidden components, sometimes there's as many as 4 old-style components out there.

 

3) If you want to store additional data in the ghx file for a specific component, you'll need to override the Read() and Write() methods. Something like this:

 

Public Overrides Function Write(ByVal writer As GH_IO.Serialization.GH_IWriter) As Boolean

  writer.SetBoolean("MySpecialBooleanValue", m_myBoolean)

  writer.SetString("MySpecialStringData", m_myString)

 

  Return MyBase.Write(writer)

End Function

 

and

 

Public Overrides Function Read(ByVal reader As GH_IO.Serialization.GH_IReader) As Boolean

  m_myBoolean = False 'Default state

  m_myString = String.Empty 'Default state

  reader.TryGetBoolean("MySpecialBooleanValue", m_myBoolean)

  reader.TryGetString("MySpecialStringData", m_myString)

 

  Return MyBase.Read(reader)

End Function

 

It is usually possible to make the Reading process smart enough to handle backwards compatibility. You can ask the reader object whether or not a certain value exists and you can then decide whether you can safely use old or new reading logic. So any changes to this part probably don't require you to create a duplicate component and hide the old one.

 

--

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