algorithmic modeling for Rhino
Hi all.
There is an additional boolean variable in my custom component (written in C#). My custom component switches its behavior if the boolean variable switched. (It is linked with ToosStripMenuItem.ClickState).
It works fine but the state of the boolean flag is not stored into the .gh file. How can I make it possible to be saved and loaded from .gh file?
Thanks.
Tags:
Hi Masaaki,
ClickState?
Anyway, if you want to (de)serialize data to a gh file beyond the standard, you'll need to override the Write() and Read() methods.
public override bool Write(GH_IO.Serialization.GH_IWriter writer)
{
writer.SetBoolean("MyCustomBooleanValue", m_booleanValue);
return base.Write(writer);
}
public override bool Read(GH_IO.Serialization.GH_IReader reader)
{
m_booleanValue = false; // the default value
reader.TryGetBoolean("MyCustomBooleanValue", ref m_booleanValue);
return base.Read(reader);
}
--
David Rutten
david@mcneel.com
Poprad, Slovakia
Thanks, David. I made it!
Can I ask one more question?
When the state of my custom component is switched, I currently clicking Recompute to reflect the new state to other components. I tried
this.ComputeData();
or
this.m_attributes.PerformLayout();
but nothing happens unless clicking Recompute or some other places in the Canvas. How can I make this automatic?
Welcome to
Grasshopper
© 2025 Created by Scott Davidson.
Powered by