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.
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SelectionEventHandler with palette

Message 1 of 5
142 Views, 4 Replies

SelectionEventHandler with palette

Is there any examples of using a select tool with a html palette to show what item clicked on?

Message 2 of 5



Here there is an example you can use:

class testCommandSelectHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
    class bodyEncoder(json.JSONEncoder):
        def default(self, obj):
            if isinstance(obj, adsk.fusion.BRepBody):
                return {'name':, 
                        'boundingBox': {
                            'minPoint': obj.boundingBox.minPoint.asArray(), 
                            'maxPoint': obj.boundingBox.maxPoint.asArray()
                        'isSolid': obj.isSolid
                return json.JSONEncoder.default(self, obj)
    def notify(self, args: adsk.core.SelectionEventArgs) -> None:
            if args.selection:
                palette = app.userInterface.palettes.itemById(PALETTE_ID)
                if palette:
                    obj = adsk.fusion.BRepBody.cast(args.selection.entity)
                    if obj:
                        palette.sendInfoToHTML('send', json.dumps(obj, cls=testCommandSelectHandler.bodyEncoder))
                        app.log(f'not body selected: ({obj})')


This is the palette.html I used:

<!DOCTYPE html>
            body {
                font-size: 16px;
                font-family: 'Roboto', sans-serif;
                color: white;
                background-color: black;
                margin: 0;
                padding: 0;
        <p>Object received:</p>
        <p id='fusionObject'></p>
        window.fusionJavaScriptHandler = {handle: function(action, data){
            try {
                if (action == 'send') {
					document.getElementById('fusionObject').innerHTML = data;
				} else if (action == 'debugger') {
				} else {
					return 'Unexpected command type: ' + action;
            } catch (e) {
                console.log('exception caught with command: ' + action + ', data: ' + data);
            return 'OK';


And this is the result once you choose a body:

Captura de pantalla 2022-07-15 141147.png


Notice that you have to build a function to serialize (convert to JSON format) the object you like to send. In this case I use the class bodyEncoder to include only the body's attributes name and boundingBox; you can include all you need there, according to the object type you choose in the selection command input (BRepBody in my case).


Hope this help. Let me know it it works for you.




Message 3 of 5

Thanks for the reply, not quite what i was trying to do.

I want to be able to recreate the fusion 360 select button inside a html palette.

Want it to act the same way have a html button that you click then you get a select tool to select a body, then once the body is selected send the selected to html.

Message 4 of 5
in reply to: WrapItToTapIt

It's not currently possible. It was discussed at one time, but there would be a lot of work to be able to support it. A possible workaround is to create a command with a dialog, where you can have the selection input, and if you need to display additional information that the current command inputs don't support you can create an HTML command input and create whatever you want in it.

Brian Ekins
Inventor and Fusion 360 API Expert
Message 5 of 5
in reply to: WrapItToTapIt

Hi @WrapItToTapIt .


The main advantage of using palettes is that they can be used as modeless dialogs.
If you really want to use a palette, I think you can use the UserInterface.activeSelectionChanged event to achieve a similar behavior. 


If you don't mind using a modal dialog, you can place a SelectionCommandInput, hide it, and use a BrowserCommandInput, and it will look the same as the palette. 

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