algorithmic modeling for Rhino

Hi there,

I have a custom component that overrides the two methods DocumentContextChanged and RemovedFromDocument. When I place this component inside a cluster which I then delete or change the context of, neither of these two methods are triggered. This makes sense in a way, because if I delete the cluster component (which contains my custom component), I am actually not deleting or changing my custom component. However, is there a way for me to link the actions performed on my cluster component to my custom component which resides inside? Basically I would like DocumentContextChanged to be triggered anytime my cluster component's DocumentContextChanged is triggered.



Views: 213

Replies to This Discussion

Progress: I've managed to listen to the cluster component's events from my custom component. I wrote this method, which simply makes the custom component (and its' document) subscribe to some events in the cluster component (and its' document).

private void SubscribeToParentDocEvents() {
GH_Document thisDoc = OnPingDocument();
if(thisDoc != null){
GH_Document parentDoc = thisDoc.Owner.OwnerDocument();
if (parentDoc != null) { //parent is null if it doesn't belong to a cluster
parentDoc.ContextChanged += OnParentContextChanged;
IGH_DocumentOwner parentOwner = thisDoc.Owner;
GH_Cluster clusterComponent = (GH_Cluster)parentOwner;
clusterComponent.ObjectChanged += ClusterComponent_ObjectChanged;
clusterComponent.SolutionExpired += ClusterComponent_SolutionExpired;
clusterComponent.PingDocument += ClusterComponent_PingDocument;

However, I am still not able to find any events in clusterComponent which are triggered when AddedToDocument and RemovedFromDocument are called. If I could find that, I think it would solve my problem. Any input?

Case closed. Found a solution - the trick was to subscribe to the parent document's events ObjectsDeleted and ObjectsAdded and then check if the any of the deleted / added objects were my specific cluster.






  • Add Photos
  • View All

© 2022   Created by Scott Davidson.   Powered by

Badges  |  Report an Issue  |  Terms of Service