Python event handling

Hi Jakob,

when a single object is transformed in the rhino document without copying it, these main events are fired in order:

Rhino.RhinoDoc.BeforeTransformObjects
Rhino.RhinoDoc.ReplaceRhinoObject
Rhino.RhinoDoc.DeleteRhinoObject
Rhino.RhinoDoc.AddRhinoObject

In case of multiple transformed objects without copying them, the BeforeTransformObjects event gets fired once for all transformed objects, but all events following are fired once for every transformed object.

Since you’re only interested in updating your component once after the transform has been performed i would setup two events, first the BeforeTransformObjects event which could give you the objects and the transform and second the Rhino.RhinoApp.Idle event which gets fired multiple times after the transform has been completed.

However there are two things to consider, first is this bug in Rhino 5 which prevents you from getting e.Objects() from the event and second, your Rhino.RhinoApp.Idle event will be fired hundrets of times in a row if you do not exit it. You might check if you subscribed to the events already as you do above and additionally use the BeforeTransformObjects event to set a global flag to True that you want to update the component in the Rhino.RhinoApp.Idle event. Then in the Idle event, check your global flag, update your component if it is True, then set this flag to False so the update is only performed once.

btw. there is much more to consider when using events. Eg. Undo and when a new document is opened, the events are still running…
_
c.

4 Likes