Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

AttributeError: 'property' object has no attribute 'add’ - MyActivateHandler

Anonymous

AttributeError: 'property' object has no attribute 'add’ - MyActivateHandler

Anonymous
Not applicable

I am trying to add my eventHandler to the Command event endpoint following the example outlined here, but I keep getting the following error.

 

Traceback (most recent call last):

  File/line(...), in <module> command_var.execute.add(onCommandExecute)

AttributeError: 'property' object has no attribute 'add’



Section of the code which is relevant was copied from one of the examples in the documentation (link😞

 

# ------- Global variables --------- After importing libraries

# Global variable used to maintain a reference to all event handlers.

handlers = []

command_var = adsk.core.Command



# -------- Event handler class definition --------- After Declaring other classes

# Event handler for the activate event.  

class MyActivateHandler(adsk.core.CommandEventHandler):

   def __init__(self):

       super().__init__()

   def notify(self, args):

       eventArgs = adsk.core.CommandEventArgs.cast(args)

 

       # Code to react to the event.

       ui.messageBox('In MyActivateHandler event handler.')

       # my final results would be getting a time stamp when a command is called and print it on a log file.



# -------- Connect the handler to the event. --------- (Bottom of the Code)

onActivate = MyActivateHandler()

command_var.activate.add(onActivate)

handlers.append(onActivate)

 

How can I solve this so that my handler is attached to the Command object and my eventHandler is triggered every time the command event is triggered.

 

I have tried to use CommandEvent.add(onActivate) instead of command_var.activate.add(onActivate), but the error this time is:

 

Traceback (most recent call last):

  File/ line (...), in <module> command_var.add(onCommandExecute)

  File/line(...) in add return _core.CommandEvent_add(self, *args)

TypeError: CommandEvent_add() takes exactly 2 arguments (1 given)



0 Likes
Reply
Accepted solutions (1)
6,950 Views
7 Replies
Replies (7)

kandennti
Mentor
Mentor

Hi @Anonymous .

 

There is too little information to consider.

1 Like

Anonymous
Not applicable

Here it's the code:


#Author- #Description- import adsk.core, adsk.fusion, adsk.cam, traceback # Global variable used to maintain a reference to all event handlers. try: app = adsk.core.Application.get() ui = app.userInterface handlers = [] command_var = adsk.core.Command except: if ui: ui.messageBox('Test Failed') def run(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface ui.messageBox('Hello addin') except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def stop(context): ui = None try: app = adsk.core.Application.get() ui = app.userInterface ui.messageBox('Stop addin') except: if ui: ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) # Event handler for the activate event. class MyActivateHandler(adsk.core.CommandEventHandler): def __init__(self): super().__init__() app = adsk.core.Application.get() ui = app.userInterface def notify(self, args): eventArgs = adsk.core.CommandEventArgs.cast(args) # Code to react to the event. ui.messageBox('In MyActivateHandler event handler.') # "command_var" is a variable referencing a Command object. try: onActivate = MyActivateHandler() command_var.activate.add(onActivate) handlers.append(onActivate) except: ui.messageBox('Handlers not set: \n{}'.format(traceback.format_exc()))
0 Likes

goyals
Autodesk
Autodesk

You are not adding activeHandler on command object instead on on ask.core.Command module which is not correct. Take a look at CommandCreatedEventHandler in http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e5c4dbe8-ee48-11e4-9823-f8b156d7cd97. You need to do something like shown in below code where the cmd object is retrieved from args object and handler is added on activate method of cmd object.

 

class CommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
handlers.append(self)
def notify(self, args):
try:
cmd = args.command
cmd.activate.add(CommandActivateHandler())



Shyam Goyal
Sr. Software Dev. Manager
1 Like

Anonymous
Not applicable

@goyals The example you linked is for a created command. I am interested in my event to be triggered when any command is triggered, and I don't want to create a new command.

 

Cheers,
P

0 Likes

goyals
Autodesk
Autodesk
Accepted solution

Please take a look at http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-47B0D239-7158-4E5E-A0BC-E784ADD55D25 to notify when any command is created and http://help.autodesk.com/view/fusion360/ENU/?guid=GUID-EBB6C82A-A256-4AB7-9A86-0F7A9653A7E9 for when any command is started.



Shyam Goyal
Sr. Software Dev. Manager
2 Likes

Anonymous
Not applicable

@goyals  It works, thank you very much!

 
0 Likes

Anonymous
Not applicable

For future references, this solution does not trigger a command when there is an explorative action (change in camera position).

 
0 Likes