Message 1 of 5
Keep a button command alive until it is pressed again
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I would like to create a button that when pressed creates a command that should stay alive until the button is pressed again (or ESC).
A similar behavior exists with the Orbit button.
In my code, however, the command is generated after the button is pressed and immediately destroyed again. It is impossible for me to keep the button in a "pressed" state.
Currently I remember the state of the button internally, but this has the disadvantage that the button is not shown as pressed (active) in the UI and also brings other problems.
Ptr<Application> app;
Ptr<UserInterface> ui;
Ptr<CommandDefinition> cmdDefinition;
Ptr<CommandControl> cmdControl;
// CommandExecuted event handler.
class MyExecuteEventHander : public adsk::core::CommandEventHandler
{
public:
void notify(const Ptr<CommandEventArgs>& eventArgs) override
{
ui->messageBox("command executed");
}
};
// CommandDestroyed event handler.
class MyDestroyEventHander : public adsk::core::CommandEventHandler
{
public:
void notify(const Ptr<CommandEventArgs>& eventArgs) override
{
ui->messageBox("command destroyed");
}
};
// CommandCreated event handler
class MyCommandCreatedEventHandler : public adsk::core::CommandCreatedEventHandler
{
public:
void notify(const Ptr<CommandCreatedEventArgs>& eventArgs) override
{
if (eventArgs)
{
auto command = eventArgs->command();
auto executeEventhHandler = command->execute()->add(&myExecuteEventHandler);
auto destroyEventHandler = command->destroy()->add(&myDestroyEventHandler);
}
}
MyExecuteEventHander myExecuteEventHandler;
MyDestroyEventHander myDestroyEventHandler;
} _commandCreatedEventHandler;
extern "C" XI_EXPORT bool run(const char* context)
{
app = Application::get();
if (!app)
return false;
ui = app->userInterface();
if (!ui)
return false;
Ptr<CommandDefinitions> commandDefinitions = app->userInterface()->commandDefinitions();
cmdDefinition = commandDefinitions->addButtonDefinition("mybutton", "Button", "");
cmdDefinition->commandCreated()->add(&_commandCreatedEventHandler);
cmdControl = app->userInterface()->workspaces()->itemById("FusionSolidEnvironment")->toolbarPanels()->itemById("UtilityPanel")->controls()->addCommand(cmdDefinition);
return true;
}
Thanks in advance.