I am trying to implement a custom message using the GH_Component.Message Property (which should appear similar to the one seen in the attached image) in visual studio in c# but I am having difficulty figuring out where the code should be executed.
The issue is that when I first drop the component on the canvas, the message does not show up until I fiddle with some inputs, but I want a default message to appear as soon as the component is placed on the canvas.
Andrew Heumann
My typical approach is to call the message updater in the class constructor, like so:
private bool some_property;
//my class constructor
My_ComponentClass() : base(blah blah blah){
some_property = true; //the default value for the component;
updateMessage();
}
//message updater
private void updateMessage()
{
if (some_property)
{
Message = "Property is True!";
}
else
{
Message = "Property is not true.";
}
}
also note that if you want the variable message property to persist through copy-paste / save / reopen, you'll need to override Read and Write functions:
public override bool Write(GH_IWriter writer)
{
writer.SetBoolean("SomeProperty", someProperty);
return base.Write(writer);
}
public override bool Read(GH_IReader reader)
{
someProperty = false;
reader.TryGetBoolean("SomeProperty", ref someProperty);
updateMessage();
return base.Read(reader);
}
Jan 16, 2015