- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I realized that I can add a check box command definition using
commandDefinitions.addCheckBoxDefinition()
However, I found little information in reference manual regarding this to answer my questions:
1. How to differentiate the state change? During my testing, I connected it with a commandCreatedEventHandler, and it is executed every time I check/un-check the check box.
2. Can I pin it to toolbar? I have set
control.isVisible = True; control.isPromoted = True; control.isPromotedByDefault = True
but the check box is not promoted to the toolbar panel.
3. Is it possible to set an icon to this checkbox? Assuming the icon has two states, which correspond to two states of a check box (enabled, disabled). I have tried setting the resource folder of the command definition using
#cmdDef: adsk.core.CommandDefinition
cmdDef.resourceFolder = <path_to_resource_folder>
but the icons are not applied.
The ultimate objective is to implement a 'state' button, which users can use it to switch between two views (one default view, another one with custom graphics groups). Please advice if this is possible to do in Fusion 360.
Any help is appreciated!
A sample code to demonstrate the problem is presented below. A resource folder with the icons is available in the attachment.
#Author-
#Description-
import adsk.core, adsk.fusion, adsk.cam, traceback
class checkBox_commandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
_ui.messageBox('Check box clicked')
_app = adsk.core.Application.get()
_ui = _app.userInterface
_handlers = []
def run(context):
try:
#Get command definitions & design workspace
cmd_def = _ui.commandDefinitions
des_wp = _ui.workspaces.itemById('FusionSolidEnvironment')
#Get tools tab
tools_tab = des_wp.toolbarTabs.itemById('ToolsTab')
#Get add-in panel
addin_panel = tools_tab.toolbarPanels.itemById('SolidScriptsAddinsPanel')
checkBox_cmdDef = cmd_def.itemById('checkBox')
if checkBox_cmdDef: checkBox_cmdDef.deleteMe()
checkBox_cmdDef = cmd_def.addCheckBoxDefinition('checkBox', 'Check box', 'Test check box', True)
checkBox_cmdDef.resourceFoler = './resources/checkBox'
checkBox_ctrl = addin_panel.controls.itemById('checkBox')
if checkBox_ctrl: checkBox_ctrl.deleteMe()
checkBox_ctrl = addin_panel.controls.addCommand(checkBox_cmdDef)
checkBox_ctrl.isVisible = True; checkBox_ctrl.isPromoted = True; checkBox_ctrl.isPromotedByDefault = True
checkBox_commandCreated = checkBox_commandCreatedEventHandler()
checkBox_cmdDef.commandCreated.add(checkBox_commandCreated)
_handlers.append(checkBox_commandCreated)
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
#Clean up the control & command definiton
cmd_def = _ui.commandDefinitions
des_wp = _ui.workspaces.itemById('FusionSolidEnvironment')
tools_tab = des_wp.toolbarTabs.itemById('ToolsTab')
addin_panel = tools_tab.toolbarPanels.itemById('SolidScriptsAddinsPanel')
checkBox_ctrl = addin_panel.controls.itemById('checkBox')
if checkBox_ctrl: checkBox_ctrl.deleteMe()
checkBox_cmdDef = cmd_def.itemById('checkBox')
if checkBox_cmdDef: checkBox_cmdDef.deleteMe()
except:
if _ui:
_ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.