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:
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.
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!
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.
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.
I know that things can be stopped as I've seen the demos . 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.
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
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.