- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have been trying to find documentation on adding a dropdown control to a ToolbarPanel. The API user manual teases by showing examples without code. Searching shows numerous examples of adding a button, but I haven't any for the dropdown.
The user manual implies that every control needs a command definition and it implies that the ListDefinition is the one for a dropdown. But the addDropDown method is not like the addCommand method. It does not have a parameter for a command definition.
Below is my code that doesn't work. What is the right way to do it?
# -*- coding: utf-8 -*- """ Created on Fri Jun 9 17:44:24 2017 Gear Generator @author: Steve Graves """ import adsk.core, adsk.fusion, adsk.cam, traceback import math # Globals _app = adsk.core.Application.cast(None) _ui = adsk.core.UserInterface.cast(None) _units = '' def run(context): try: global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface createPanel = _ui.allToolbarPanels.itemById('SolidCreatePanel') dropCmdDefGear = _ui.commandDefinitions.addListDefinition('smgDropGearGenList', 'Gear Generator', adsk.core.ListControlDisplayTypes.StandardListType) dropGear = createPanel.controls.addDropDown('Gear Generator','', 'smgDropGearGen') #Resources/GearGen cmdGearPlanetDef = _ui.commandDefinitions.addButtonDefinition('smgCmdGearGenPlanet', 'Planetary Gears', 'Creates a planetary gear component', '') #Resources/GearGen planetGearButton = dropGear.controls.addCommand(cmdGearPlanetDef) if context['IsApplicationStartup'] == False: _ui.messageBox('The "Gear Generator" commands have been added\nto the CREATE panel of the MODEL workspace.') except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def stop(context): try: createPanel = _ui.allToolbarPanels.itemById('SolidCreatePanel') planetGearButton = createPanel.controls.itemById('smgCmdGearGenPlanet') if planetGearButton: planetGearButton.deleteMe() cmdDef = _ui.commandDefinitions.itemById('smgCmdGearGenPlanet') if cmdDef: cmdDef.deleteMe() cmdDef = _ui.commandDefinitions.itemById('smgDropGearGenList') if cmdDef: cmdDef.deleteMe() dropCtl = createPanel.controls.itemById('smgDropGearGen') if dropCtl: dropCtl.deleteMe() except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.