OnActivateCommand not firing for my command

<?xml encoding=”UTF-8″>By Adam Nagy

Built-in Inventor commands in general are expected to fire the OnActivateCommand event of the UserInputEvents object and set the ActiveCommand property of the CommandManager object.
However, some of them do not for the following reason (which is the same reason your command might not fire it either): no interaction has been started.

To start an interaction you need to create an InteractionEvents object and call its Start function at the beginning of your command and its Stop function at the end. 
You should also name the interaction, which then will show up as the CommandName parameter in the OnActivateCommand / OnTerminateCommand events, and as the ActiveCommand property of the CommandManager object.

// My command's OnExecute handler
void m_btnDef_OnExecute(NameValueMap Context)
{
// Start interaction
CommandManager cmdMgr = m_inventorApplication.CommandManager;
InteractionEvents intEvents = cmdMgr.CreateInteractionEvents();
intEvents.Name = m_btnDef.InternalName;
intEvents.Start(); // OnActivateCommand fires
// My command's implementation goes here
// If during this time the CommandManager.ActiveCommand is accessed
// it will retrieve the value we set to intEvents.Name
// Stop interaction
intEvents.Stop();
}
// OnTerminateCommand fires once interaction is stopped and
// control got back to Inventor 

Example

ActiveCommand

 


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading