Showing results for 
Search instead for 
Did you mean: 

Command 'activation'


I've created a 2D Drafting Addin with ribbon in C# from Jason's templates.  I currently have a button that when clicked, looks at the select set and for each item in it, if it is a dimension, it applies a custom format to that dimension.


Although this works fine, I would like to be able to 'activate' the command by clicking the button and have it highlighted or something, then click dimensions in the view to format them. Then deactivate the command by Esc or right click. I.e. I'd like it to work more like the built in SE commands.


I don't necessarily want exact code, but what's the workflow to achieve this? 


Re: Command 'activation'

Solution Partner Legend Solution Partner Legend
Solution Partner Legend

Hi Alex_H,


for your purpose exist the Command object and its Mouse property. The workflow would be as follows:


On click of your button you create an instance of the Command object and assign its Mouse property to a corresponding Mouse object. Now you configure your Command and Mouse objects. I.e. assign an event handler method for the mouse click event. In the mouse click event you will be able to locate the clicked object and in case of a dimension object perform your formatting. With the Start() method of your command instance you start the command and it behaves like a built in command.

Keyboard events (like detecting the press of the ESC key) can be handled by your program as usual. In the corresponding event handler for a key press of the ESC key you can terminate your started command instance by setting its property Done to true.


Jason has provided good examples of how to use the Command and Mouse objects in his examples downloadable on github.


Kind regards,
Wolfgang Kunert -

Re: Command 'activation'

Solution Partner Phenom Solution Partner Phenom
Solution Partner Phenom

You bring up a good point though. I should add how to do this in the DemoAddin on GitHub. I'll do that and get back with you.

Jason Newell
Applications Architect

Re: Command 'activation'


Thanks Wku, that's a good explanation. Also, Jason, a working example would be great.