onSlection event

onSlection event

JanNavratil
Advocate Advocate
1,115 Views
4 Replies
Message 1 of 5

onSlection event

JanNavratil
Advocate
Advocate

Hello,

 

I'm trying to create small addin to get the velues on select of random things in the graphic windows.
I was thinking that this should be ok but, I'm not getting anything when I select entity.

# Event handler for the select event.
class MySelectHandler(adsk.core.SelectionEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
eventArgs = adsk.core.SelectionEventArgs.cast(args)

# Code to react to the event.
ui.messageBox('In MySelectHandler event handler.')

 Is there any sample of event on select? with message box or something?

Can any1 help me please?

Thanks,
Jan

0 Likes
Accepted solutions (1)
1,116 Views
4 Replies
Replies (4)
Message 2 of 5

kandennti
Mentor
Mentor
Accepted solution

Hi @JanNavratil .

 

It is necessary to implement what is described in Help.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ACFFC2F-458B-4740-93B8-CCC56638D8AA 

 

I made a simple Select Event sample.
I think you will need a code that is at least this long.

#Fusion360API Python script
#Author-kantoku
#Description-Select Event Sample

import adsk.core, adsk.fusion, traceback

_commandId = 'SelectionEvent'
_SelIpt1ID = 'Selectioninput1'

_handlers = []
_app = None
_ui = None

class CommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

# Event handler for the select event.
# https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-2ACFFC2F-458B-4740-93B8-CCC56638D8AA
class MySelectHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.SelectionEventArgs.cast(args)

        # Code to react to the event.
        _ui.messageBox('In MySelectHandler event handler.')

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd :adsk.core.Command = args.command

            onDestroy = CommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onSelect = MySelectHandler()
            cmd.select.add(onSelect)
            _handlers.append(onSelect)

            inputs = cmd.commandInputs
            i1 = inputs.addSelectionInput(_SelIpt1ID, _SelIpt1ID,  _SelIpt1ID)
            i1.setSelectionLimits(0)

        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDefs = _ui.commandDefinitions

        cmdDef = cmdDefs.itemById(_commandId)
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)

        onCmdCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCmdCreated)
        _handlers.append(onCmdCreated)
        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 5

JanNavratil
Advocate
Advocate

Thank you for the sample. cool!

 

Jan

0 Likes
Message 4 of 5

JanNavratil
Advocate
Advocate

Again, thank you !
Can I ask you, is there event for CAM strategy creation or toolpath in manufacturing part?

I was not able to find it in the documentation.

 

Jan

0 Likes
Message 5 of 5

kandennti
Mentor
Mentor

If you look at this Derived Classes, there seems to be no event related to CAM.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-8fe1eb12-c1dd-4bb5-b8f5-18ec63a5f464 

 

If you use the Application.registerCustomEvent method, you may be able to do something, but it seems difficult.

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-29BB6E92-6553-4AF8-B00E-63B8956B44B3