Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Can you have a Single Event Handler to handle multiple events?

1 REPLY 1
Reply
Message 1 of 2
markusbarnes
375 Views, 1 Reply

Can you have a Single Event Handler to handle multiple events?

From my understanding, if you want to respond to the CommandCreatedEvent and ValidateInputsEvent for instance, you must subclass and override CommandCreatedEventHandler and ValidateInputsEventHandler.  You then need to connect their instances to the control's commands. 

 

Is it possible to create a single event handler object to handle multiple event types such as CommandCreatedEvent and ValidateInputEvent? My guess is that the event and event handler classes may be too closely coupled to allow this. My current thought is that you can use c++ multiple inheritance to do this:

class My360Command : ValidateInputsEvent , CommandCreatedEventHandler
{
     ..... // Fusion 360 Event notification overrides
     void notify(const Ptr<CommandCreatedEventArgs>& eventArgs) override;
     void notify(const Ptr<ValidateInputsEventEventArgs>& eventArgs) override;
} 

Is it possible to do this or is there a better way?  

 

1 REPLY 1
Message 2 of 2
rudisoft
in reply to: markusbarnes

I tried it this way:

 

class MyCmdValidateInputsEventHandler : public adsk::core::ValidateInputsEventHandler
{
public:
void notify(const Ptr<ValidateInputsEventArgs>& eventArgs) override
{
Ptr<Application> app = Application::get();
Ptr<UserInterface>ui = app->userInterface();
Ptr<Event> evt= eventArgs->firingEvent();
// proceed here with whatever you wanted to do } } _myCmdValidateInputs;   class MyCmdCreatedHandler : public adsk::core::CommandCreatedEventHandler {
// I'm not sure if this nesting is actually necessary but it works void notify(const Ptr<CommandCreatedEventArgs>& eventArgs) override { Ptr<Design> des = _app->activeProduct(); Ptr<Command> cmd = eventArgs->command(); cmd->isExecutedWhenPreEmpted(false); cmd->validateInputs()->add(&_myCmdValidateInputs); } _myCmdCreated; extern "C" XI_EXPORT bool run(const char* context) { _app = Application::get(); _ui = _app->userInterface(); Ptr<CommandDefinitions> cmdDefs = _ui->commandDefinitions(); Ptr<CommandDefinition> myDesignCmdDef = cmdDefs->itemById(myHypoDesignCmdDefID); if (!myDesignCmdDef) { hypoDesignCmdDef = cmdDefs->addButtonDefinition(adskHypoDesignCmdDefID, "Hypocycloid gears", "Awesome gears ahead", "Resources"); } myDesignCmdDef->commandCreated()->add(&_myCmdCreated); return true; }

 

Tags (1)

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report