Fusion 360 API Component priority

Fusion 360 API Component priority

n.michiels
Contributor Contributor
1,065 Views
3 Replies
Message 1 of 4

Fusion 360 API Component priority

n.michiels
Contributor
Contributor

Hello All,

Does someone by any chance know how to enable the select component priority, by using the API?

nmichiels_0-1725286401806.png

 

Thank you!

 

Regards,

Nick

0 Likes
Accepted solutions (1)
1,066 Views
3 Replies
Replies (3)
Message 2 of 4

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

Hi,

 

This are the command IDs for the selection priorities:

    <CommandControl name="Select Body Priority" id="SelectBodyPriorityCommand" commandType="ButtonControlDefinition" isPromoted="False" />
    <CommandControl name="Select Face Priority" id="SelectFacePriorityCommand" commandType="ButtonControlDefinition" isPromoted="False" />
    <CommandControl name="Select Edge Priority" id="SelectEdgePriorityCommand" commandType="ButtonControlDefinition" isPromoted="False" />
    <CommandControl name="Select Component Priority" id="SelectComponentPriorityCommand" commandType="ButtonControlDefinition" isPromoted="False" />

 

You can use its ID to toggle its selection, either with CommandDefinition.execute()  or with a text command like so:

    Commands.Start SelectComponentPriorityCommand

 

Regards,

Jorge Jaramillo

 

Message 3 of 4

n.michiels
Contributor
Contributor

Hello,

Sorry that I still not fully understand your example. I am still a beginner. 

I am using Python btw.

regards.

0 Likes
Message 4 of 4

Jorge_Jaramillo
Collaborator
Collaborator

Hi,

 

The XML extract that I sent you in the last message is how the Fusion UI Menus are defined; from there I extract the commands ID for the different selection priorities you find in the menu.

Then you can use that Command Definition Id to look for it and execute it (as you do when you create a command dialog where you first define a command definition and the execute it): I found two option to execute it. They are equivalent, so you can can choose any of them.

 

This is the source code with the two options:

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

app = adsk.core.Application.get()

def option_command_definition(cmdId : str) -> None:
    cmd_def = app.userInterface.commandDefinitions.itemById(cmdId)
    if cmd_def:
        cmd_def.execute()
        app.log(f'{cmdId} was toggled by CommandDefinition')
    else:
        app.log(f'Command definition "{cmdId}" not found!')

def option_text_command(cmdId: str) -> None:
    ret = app.executeTextCommand(f'Commands.Start {cmdId}')
    app.log(f'{cmdId} toggled by Text Command with result : {ret}')

def run(context) -> None:
    try:
        # Option 1 : by Command Definition
        option_command_definition("SelectComponentPriorityCommand")

        # Option 2 : by Text Command
        # option_text_command("SelectComponentPriorityCommand")
    except:
        app.log('Failed:\n{}'.format(traceback.format_exc()))
    adsk.terminate()

 

I hope this can help you.

 

Regards,

Jorge Jaramillo

 

0 Likes