When adding an event to the GH_Document
corresponding to a component in GH_Component.AddedToDocument()
, it may not be added correctly.
I am trying to add an event to a document in GH_Component
as follows
public void TestDocumentSettingChenged(Object sender, GH_DocSettingsEventArgs e)
{
RhinoApp.WriteLine($"TestCheckSettingChenged: {InstanceGuid}");
}
public override void AddedToDocument(GH_Document document)
{
base.AddedToDocument(document);
document.SettingsChanged += TestDocumentSettingChenged;
}
When executed, there were cases of unintended behavior as follows.
When adding a component from a panel or search box when loading a GH file, I can correctly add an event to the document by adding a method to the SettingsChanged
event for the GH_Document
object in the argument.
However, when the AddToDocument()
method is called during copy and paste or duplication on the canvas, the event cannot be added. It runs without error, but does not seem to actually add the intended method to the intended document event.
I would like to know how to add events from the component to the document for various cases. Thank you in advance.