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: 

Accessing Add-Ins panel in Fusion 360 and creating items under it

7 REPLIES 7
Reply
Message 1 of 8
nate_webers
1215 Views, 7 Replies

Accessing Add-Ins panel in Fusion 360 and creating items under it

As I am preparing to publish an add-in for Fusion 360, I saw in a guideline (http://usa.autodesk.com/adsk/servlet/item?siteID=123112&id=24734968) that it is preferred that add-ins to under the "add-ins" panel as opposed to creating your own panel (which I presently do. This was done several months ago before "add-ins" first appeared in the UI).

 

I need to know two things:

 

  1. How do I access the "Add-ins" panel?  If the Add-ins panel for "Model" is different than the one that is under "CAM", I need to know how to differentiate between the two.
  2. Once I do gain access to the (proper) Add-ins panel, I have three commands that I need to insert.  How do I create an item under the Add-Ins menu that would contain three items underneath it (one for each command... similar to what is observed when you are in the "Model" toolbar and you choose Create->Pattern and you see three sub-commands)?  Also, is it possible to have an icon next to the primary menu item (in other words, an icon next to the "Pattern" item that is in the "Create" menu)?
Tags (2)
7 REPLIES 7
Message 2 of 8
liujac
in reply to: nate_webers

  1. The id of the Add-ins panel for “Model” is “SolidScriptsAddinsPanel”. The id of the Add-ins panel for “CAM” is “CAMScriptsAddinsPanel”. So you can get the Add-ins panel you want by id. Also you can get the toolbar panels by specified workspace.
  2. You can add a DropDownControl to the Add-ins panel, and then add the sub commands under the DropDownControl. You can set the resource folder containing the image used for the icon.

Here is the script to demo how to add a DropDownControl to the Add-ins panel for “Model”:

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

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
            
        addins = adsk.core.ToolbarPanel.cast(ui.allToolbarPanels.itemById("SolidScriptsAddinsPanel"))
        dropDown = addins.controls.addDropDown("DropDown", "./resources")
        cmd0 = ui.commandDefinitions.addButtonDefinition("cmd0", "Command One", "Command One Tooltip", "./resources")
        cmd1 = ui.commandDefinitions.addButtonDefinition("cmd1", "Command Two", "Command Two Tooltip", "./resources")
        dropDown.controls.addCommand(cmd0)
        dropDown.controls.addCommand(cmd1)

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

Here is a sample writes out all of the controls in the Fusion UI to a specified text file: http://help.autodesk.com/view/NINVFUS/ENU/?guid=GUID-d2b85a7e-fd08-11e4-9e07-3417ebd3d5be. This is very useful when positioning your controls within existing Fusion toolbars and panels and positioning your command adjacent to an existing command.

Message 3 of 8
nate_webers
in reply to: liujac

This is helpful, but I have two questions:

 

1) A "?" appears next to my drop-down item.  How do I change it with a different icon (I haven't found the property to change it, unlike my individual commands).

 

2) What is the most efficient way to remove the command items if someone were to stop my script?

 

Thanks for the help so far!

Message 4 of 8
nate_webers
in reply to: nate_webers

I figured out the answer to question 1 by simply pointing the resource folder to the appropriate resource. 

 

I just need help with quesiton 2, removing the sub-command items in the drop-down and removing the drop-down itself.

Message 5 of 8
ekinsb
in reply to: nate_webers

You can add code to the stop function of your add-in to remove any of your UI.  This is demonstrated in any of the sample add-ins.  It's also painfully apparent that the documentation needs some work in this area.


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 6 of 8
nate_webers
in reply to: ekinsb

I know that things can be stopped as I've seen the demos Smiley Happy.  I'm just trying to get it to work for the new drop-down I produced.

 

As it is, I can stop the command functionality of the items I created, I just can't get rid of the items from the drop-down or the drop-down itself.  It's likely a matter of figuring out how to access the items again.

Message 7 of 8
ekinsb
in reply to: nate_webers

When you create a new add-in, it contains the "run" and "stop" functions.  Fusion calls the run function when it starts your add-in and that's where you're creating your commands, adding your buttons into the UI, and connecting to command related events.  There is also the stop function which Fusion calls when your add-in is being unloaded.  For example, if the user stops your add-in through the "Scripts and Add-Ins" dialog, Fusion will call the stop function.  Inside the stop function you can remove any of the UI that you've added.  Here's a link to several relatively simple add-ins that demonstrate that.

 

https://github.com/brianekins/FusionHackathonSamples

 


Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 8 of 8
nate_webers
in reply to: ekinsb

I got it.  I was able to add the drop-down itself to my array of things to be removed without worrying about the sub-items.  When I did that, my removal code now works fine.  I can repeatedly start and stop the add-in with no bad effects.

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