Announcements
Autodesk Community will be read-only between April 26 and April 27 as we complete essential maintenance. We will remove this banner once completed. Thanks for your understanding

Add Fusion 360 command to add in menu

brad.bylls
Collaborator Collaborator
468 Views
1 Reply
Message 1 of 2

Add Fusion 360 command to add in menu

brad.bylls
Collaborator
Collaborator

How can I add the 'Add Thread' Fusion command to my addin menu to make it more convenient for the user? 

Brad Bylls
Reply
Reply
0 Likes
Accepted solutions (1)
469 Views
1 Reply
Reply (1)
Message 2 of 2

BrianEkins
Mentor
Mentor
Accepted solution

All commands, both the internal commands and those created by add-ins, exist internally as CommandDefinition objects. You can access all Command Definitions object through the UserInterface.commandDefinitions property which returns a CommandDefinitions object.  This lets you traverse over all of the existing commands, or if you know the ID of the command you want you can use the itemById method to get a specific CommandDefinition.  The ID for the Thread command is "FusionThreadCommand".

 

To find out the name of a specific command, I used the script below to write out a list of all the existing commands.  Using the "Find" command in a text editor will usually let you quickly find the command and its ID.

 

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        result = ''
        cmdDef = adsk.core.CommandDefinition.cast(None)
        for cmdDef in ui.commandDefinitions:
            result += cmdDef.name + ', ' + cmdDef.id + '\n'

        output = open('C:/Temp/FusionCommands.txt', 'w')
        output.writelines(result)
        output.close()

        ui.messageBox('Finished writing to "C:/Temp/FusionCommands.txt"')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

 

With the CommandDefinition you've obtained you can create a button for it, the same as you do for any commands you create.

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
Reply
Reply
0 Likes