<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Triggering event after any mouseclick using Command.mouseClick Event in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9838864#M10251</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm 99.99% certain that the API does not have access to the main F360 application events - in general, it only allows you to access events associated with commands and commandInputs that you create as part of your addIn/script.&amp;nbsp; &amp;nbsp;You need to create a command/commandInput, and as part of the creation event, you add the mouseClick.&amp;nbsp; Unfortunately, the API doesn't have the event hooks to allow you to do what you want, at least not without a significant work around (if that is even possible).&amp;nbsp; This means that the command you create has to be active in order to capture the event. However the major problem is that only one command can be active at the same time!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure there are many of us who would be interested in a work around.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
    <pubDate>Mon, 02 Nov 2020 00:41:47 GMT</pubDate>
    <dc:creator>pludikar</dc:creator>
    <dc:date>2020-11-02T00:41:47Z</dc:date>
    <item>
      <title>Triggering event after any mouseclick using Command.mouseClick Event</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9838663#M10250</link>
      <description>&lt;P&gt;Good evening,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem: &lt;/STRONG&gt;When I run the code at the bottom I get the following error:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;Handlers not set:
  Traceback (most recent call last):
  File "....", line... in &amp;lt;module&amp;gt;
  command_var.mouseClick.add(onMouseClick)
AttributeError: 'property' object has no attribute 'add'&lt;/LI-CODE&gt;&lt;P&gt;In the example in the &lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-8a01c72c-e5d6-40c2-a7d8-f00fe170df1f" target="_blank" rel="noopener"&gt;documentation&lt;/A&gt;, there is no detail on how the `&lt;EM&gt;comand_var&lt;/EM&gt;` variable was defined.&lt;/P&gt;&lt;P&gt;When I inspect the comand_var variable in VSC I can see that it is referenced to the class&amp;nbsp; Command() and not the Command object.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Why:&amp;nbsp;&lt;/STRONG&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;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())) &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 01 Nov 2020 20:27:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9838663#M10250</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-01T20:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Triggering event after any mouseclick using Command.mouseClick Event</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9838864#M10251</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm 99.99% certain that the API does not have access to the main F360 application events - in general, it only allows you to access events associated with commands and commandInputs that you create as part of your addIn/script.&amp;nbsp; &amp;nbsp;You need to create a command/commandInput, and as part of the creation event, you add the mouseClick.&amp;nbsp; Unfortunately, the API doesn't have the event hooks to allow you to do what you want, at least not without a significant work around (if that is even possible).&amp;nbsp; This means that the command you create has to be active in order to capture the event. However the major problem is that only one command can be active at the same time!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm sure there are many of us who would be interested in a work around.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Peter&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 00:41:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9838864#M10251</guid>
      <dc:creator>pludikar</dc:creator>
      <dc:date>2020-11-02T00:41:47Z</dc:date>
    </item>
    <item>
      <title>Re: Triggering event after any mouseclick using Command.mouseClick Event</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9839057#M10252</link>
      <description>&lt;P&gt;Please take a look at this&amp;nbsp;&lt;A href="https://adndevblog.typepad.com/manufacturing/page/6/" target="_blank"&gt;https://adndevblog.typepad.com/manufacturing/page/6/&lt;/A&gt;&amp;nbsp;explaining how to add mouse click event to a command. Thanks.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 04:03:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9839057#M10252</guid>
      <dc:creator>goyals</dc:creator>
      <dc:date>2020-11-02T04:03:42Z</dc:date>
    </item>
    <item>
      <title>Re: Triggering event after any mouseclick using Command.mouseClick Event</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9839409#M10253</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;EDIT:&lt;/STRONG&gt; The MouseClick event should be running in the background so that, for example, the number of times a user clicks on the circle tool in the sketch environment are recorded. I thought I could add the mouseClick handler to Command object of all commands, or a similar workaround.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/1639694"&gt;@goyals&lt;/a&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;For now, I have managed to use the&amp;nbsp;&amp;nbsp;&lt;/EM&gt;&lt;SPAN style="font-family: inherit;"&gt;ApplicationCommandEventHandler and adding it to the&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;commandStarting object&lt;/SPAN&gt;&lt;EM&gt;, but this only gets triggered once when a user is creating circles in a sketch environment, so I am unaware of how many times the command is used (The sketch is an example, but definitely a case that I would like to be able to solve).&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3042732"&gt;@pludikar&lt;/a&gt;&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Thanks&lt;/EM&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 02 Nov 2020 10:06:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/triggering-event-after-any-mouseclick-using-command-mouseclick/m-p/9839409#M10253</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-11-02T10:06:45Z</dc:date>
    </item>
  </channel>
</rss>

