Command.activate Event

Parent Object: Command
Defined in namespace "adsk::core" and the header file is <Core/UserInterface/Command.h>

Description

Gets an event that is fired when the command is first activated or re-activated after being suspended.

Syntax

-------- Import ---------
# Import fusion360utils folder, which includes event_utils.py.
from ...lib import fusion360utils as futil

-------- Global variables ---------
# Global variable used to maintain a reference to all event handlers.
local_handlers = []

-------- Connect the handler to the event. ---------
# "command_var" is a variable referencing a Command object.
# "command_activate" is the event handler function.
futil.add_handler(command_var.activate, command_activate, local_handlers=local_handlers)

-------- Event handler function definition ---------
# Event handler for the activate event.
def command_activate(args: adsk.core.CommandEventArgs):
# Code to react to the event.
app.log('In command_activate event handler.')
-------- Global variables ---------
# Global variable used to maintain a reference to all event handlers.
handlers = []

-------- Connect the handler to the event. ---------
# "command_var" is a variable referencing a Command object.
# "MyActivateHandler" is the name of the class that handles the event.
onActivate = MyActivateHandler()
command_var.activate.add(onActivate)
handlers.append(onActivate)

-------- Event handler class definition ---------
# Event handler for the activate event.
class MyActivateHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args: adsk.core.CommandEventArgs):
# Code to react to the event.
app.log('In MyActivateHandler event handler.')
--------- Required include files. ---------
#include <Core/UserInterface/Command.h>
#include <Core/UserInterface/CommandEvent.h>
#include <Core/UserInterface/CommandEventHandler.h>
#include <Core/UserInterface/CommandEventArgs.h>


--------- Event handler class definition and global declaration. ---------
// Event handler for the activate event.
class MyActivateEventHandler : public adsk::core::CommandEventHandler
{
public:
void notify(const Ptr<CommandEventArgs>& eventArgs) override
{
// Code to react to the event.
ui->messageBox("In MyActivateEventHandler event handler.");
}
} _activate;

--------- Connect the handler to the event. ---------
// "command_var" is a variable referencing a Command object.
// Connect the handler function to the event.
Ptr<CommandEvent> activateEvent = command_var->activate();
if (!activateEvent)
return;

bool isOk = activateEvent->add(&_activate);
if (!isOk)
return;

Property Value

This is an event property that returns a CommandEvent.

Return Value

Type Description
CommandEvent Returns a CommandEvent object that is used to connect and release from the event.

Version

Introduced in version August 2014