Community
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?
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; }