What command is active?

What command is active?

tobias_wiesendanger
Advocate Advocate
476 Views
6 Replies
Message 1 of 7

What command is active?

tobias_wiesendanger
Advocate
Advocate

I know that there is something like this: invApp.CommandManager.ActiveCommand which tells me what command is active. The problem im facing is, on fast pc's if a command is clicked this will be the button you just clicked and on slower pc's it looks like it is the command that was active before clicking the button. (Not 100% sure if thats the case, but it looks like it)

 

I need to now what command was active before clicking the button. Depending on what it was the method should immediately return. Any ideas how to achieve that?

0 Likes
Accepted solutions (1)
477 Views
6 Replies
Replies (6)
Message 2 of 7

WCrihfield
Mentor
Mentor

Hi @tobias_wiesendanger.  That is a tough one.  Are you just talking about any given button in Inventor's user interface, or are you talking about a button for a custom Inventor add-in that you have control over?  If you have access to that specific ControlDefinition, then your add-in will receive the notification of the Click event.  But if it is not add-in related, then the main thing that comes to mind is maybe attempting to monitor the UserInputEvents.OnActivateCommand Event, and the UserInputEvents.OnTerminateCommand Event.  Those Events will of course be triggered a ton, so the code used for monitoring them would need to be pretty efficient to avoid slowing Inventor down.  On the down side of using those events is that although they both have a 'Context' (NameValueMap), neither of them currently offer any information within that Context, so they are fairly basic.

Wesley Crihfield

EESignature

(Not an Autodesk Employee)

0 Likes
Message 3 of 7

tobias_wiesendanger
Advocate
Advocate

It is addin related. So the button that is clicked is from my addin but I dont think that changes anything. 

 

The idea with the command events is a good one. I think I will try that one. The code would be very efficient because I could just set the last command that was used.

0 Likes
Message 4 of 7

Frederick_Law
Mentor
Mentor

Or check the undo list.

0 Likes
Message 5 of 7

tobias_wiesendanger
Advocate
Advocate

Not sure how the undo list should help?

 

Events seam tricky as well. Depending on the system they are firing before or after the method.

0 Likes
Message 6 of 7

Frederick_Law
Mentor
Mentor

It collect commands since last save.

Maybe able to find command before button click.

It's transaction in API:

https://help.autodesk.com/view/INVNTOR/2023/ENU/?guid=GUID-EB4D4D34-C84F-494A-8665-D87EF536B38F

0 Likes
Message 7 of 7

tobias_wiesendanger
Advocate
Advocate
Accepted solution

Yeah but only if you started a transaction before, which I cannot do. I do a  invApp.CommandManager.StopActiveCommand(); before now. This should work for my case.