
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
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)
Solved! Go to Solution.