Message 1 of 5
Adding an input to a command dynamically
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I am trying to make a command with an add/remove pair of button whose effects would make new inputs appear in the command panel.
I work on a Mac.
I can't get the new control to appear in the panel, here is the code:
from adsk.core import *
import traceback
SETTINGS_COMMAND_KEY = 'TestCmd'
keepHandlers = []
deleters = []
def handle(handler, clazz):
class Handler(clazz):
def notify(self, args):
try:
handler(args)
except:
Application.get().userInterface.messageBox('Failed:\n{}'.format(traceback.format_exc()))
handler_instance = Handler()
keepHandlers.append(handler_instance)
return handler_instance
def delete_control(controls, command_key):
control = controls.itemById(command_key)
if control:
control.deleteMe()
def replace_existing_control(controls, new_command):
delete_control(controls, new_command.id)
if new_command:
control = controls.addCommand(new_command)
return lambda: control.deleteMe()
return lambda: None
def create_setting_panel(args):
app = Application.get()
ui = app.userInterface
cmd = Command.cast(args.command)
inputs = cmd.commandInputs
def on_input_change(args):
ui.messageBox('click')
new_input = inputs.addBoolValueInput('sqf', 'Add sqf', False, '', True)
new_input.isVisible = True
inputs.addBoolValueInput('addExport', 'Add Export', False, '', True)
cmd.inputChanged.add(handle(on_input_change, InputChangedEventHandler))
def run(context):
app = Application.get()
ui = app.userInterface
try:
cmd_defs = ui.commandDefinitions
settings_command = ui.commandDefinitions.itemById(SETTINGS_COMMAND_KEY)
if settings_command:
settings_command.deleteMe()
settings_command = cmd_defs.addButtonDefinition(SETTINGS_COMMAND_KEY, 'Test', 'Test', '')
settings_command.commandCreated.add(handle(create_setting_panel, CommandCreatedEventHandler))
deleters.append(
replace_existing_control(ui.allToolbarPanels.itemById('SolidMakePanel').controls, settings_command))
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
ui = None
try:
app = Application.get()
ui = app.userInterface
global keepHandlers
keepHandlers = []
for obj in deleters:
obj()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
I see the messagebox appearing with the "click", but the new button doesn't appear in the box.
Is there a time window to add inputs to a command?
The UI example with the TableComandInput is a bit confusing and, I suspect, buggy (some stray controls appear under the table when I run it, and they don't disappear when I remove the row).
I can't use directly use a table system anyways since they don't accept SelectionInputs.
Thanks all for your help.
Nicolas.
