Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Events/Handlers for sketch selections and UserParameters

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
william-c-anderson
422 Views, 2 Replies

Events/Handlers for sketch selections and UserParameters

Is there a UI event (and associated handler) for when a new selection is made in the active sketch?

 

Similarly, is there an event/handler for when a change is made to UserParameters?

 

I'm interested in designing a new class in Python derived from SketchEntity, and this class will need to see when a member of its type is selected, as well as when a change is made to UserParameters.

2 REPLIES 2
Message 2 of 3

Hi @william-c-anderson .

 

It is interpreted that UserParameters changes are made in the GUI.
The following code displays a dialog when the OK button is pressed.

1.png

#Fusion360 python adinn

import adsk.core, adsk.fusion, adsk.cam, traceback

_handlers = []
_app = adsk.core.Application.cast(None)
_ui = adsk.core.UserInterface.cast(None)

class CommandHandler(adsk.core.ApplicationCommandEventHandler):
    def __init__(self, targetCommand):
        super().__init__()
        self.tgtCmd = targetCommand
    def notify(self, args):
        try:
            if _ui.activeCommand == self.tgtCmd:
                # Here, the change of UserParameters is checked.
                _ui.messageBox('call ' + self.tgtCmd)

        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

        onCommand = CommandHandler('ChangeParameterCommand')
        _ui.commandTerminated.add(onCommand)
        _handlers.append(onCommand)
        print('--- Start addin ---')

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

def stop(context):
    try:
        for hdl in _handlers:
            _ui.commandTerminated.remove(hdl)
        _handlers.clear()
        print('--- Stop addin ---')

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


At this point, you should check that UserParameters has changed since the previous call.

Message 3 of 3

どうもありがとう, @kandennti ! Just what I needed this morning.

I've decided to give up on the idea of a derived class (no way to "pickle" the Python class instance to make it persistent, I'm guessing), but I think I have another way to accomplish my task.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report