C++ Plugin, how to handle AddRhinoObject, DeleteRhinoObject, etc?

I have a working C++ plugin with several commands.

Now I want my plugin to react when an object is added, edited or deleted. I found the sample for https://developer.rhino3d.com/guides/cpp/custom-undo-events/, but having trouble translating that to how to correctly implement add/edit/delete handlers in my code. (From what I have read so far, it appears that an edit = delete+add, so a separate edit handler may not be needed.)

Hi @mgraham,

To handle Rhino events, you will want to inherit a class from CRhinoEventWatcher and override the virtual functions related to the events you are interested in.

There is sample worth reviewing in the developer samples repository on GitHub.

SampleEventWatcher

– Dale

That was very helpful, thanks

Related question, can I turn the watcher on and off from another command? I want to add a dialog to allow the user to toggle the watcher state.

Of course - the sample command in the project does this.

cmdSampleEventWatcher.cpp

– Dale

I see, can replace the command line prompts with a call to my dialog, which makes more sense than what I was envisioning.