Message 1 of 4
Triggering event after any mouseclick using Command.mouseClick Event

Not applicable
11-01-2020
12:27 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Good evening,
I am trying to connect a handler to the Mouse event so that I can monitor how many clicks a user makes in a specific environment in Fusion. Ultimately I would like to do the same with the keyboard.
Problem: When I run the code at the bottom I get the following error:
Handlers not set:
Traceback (most recent call last):
File "....", line... in <module>
command_var.mouseClick.add(onMouseClick)
AttributeError: 'property' object has no attribute 'add'
In the example in the documentation, there is no detail on how the `comand_var` variable was defined.
When I inspect the comand_var variable in VSC I can see that it is referenced to the class Command() and not the Command object.
Why: The project I am working on could use this as a metric of activity of a user in a specific environment. Further work could develop an educational tool or inform educators on students drafting strategies.
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
camera = app.cameraChanged
_activeEditObject = app.activeEditObject
cmd = adsk.core.Command
#keyboard = adsk.core.KeyboardEvent
# Global variable used to maintain a reference to all event handlers.
handlers = []
command_var = adsk.core.Command
except:
if ui:
ui.messageBox('Error:\n{}'.format(traceback.format_exc()))
# Event handler for the mouseClick event.
class MyMouseClickHandler(adsk.core.MouseEventHandler):
def __init__(self):
super().__init__()
app =adsk.core.Application.get()
ui = app.userInterface
def notify(self, args):
eventArgs = adsk.core.MouseEventArgs.cast(args)
try:
ui = adsk.core.Application.get().userInterface
ui.messageBox('MyMouseClickHandler triggered')
except:
ui = adsk.core.Application.get().userInterface
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
#KeyboardEventHandler
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()))
# setup handlers to trigger loggers
try:
onMouseClick = MyMouseClickHandler()
ui.messageBox(str(type(command_var)))
command_var.mouseClick.add(onMouseClick)
handlers.append(onMouseClick)
except:
ui.messageBox('Handlers not set: \n{}'.format(traceback.format_exc()))