- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hello everyone. It will be helpful if you can tell me.
I am testing a script(addButtonDefinition) with two SelectionCommandInput.
The desired method is to enable the OK button only when two SelectionCommandInputs are selected, and to disable the button otherwise.
I understand that you can control the OK button with the areInputsValid property of the ValidateInputsEventArgs object.
However, the firing of ValidateInputsEvent is the timing when two SelectionCommandInputs are selected.
In the following code, if one is selected, the OK button will be enabled and the ValidateInputsEvent will not occur, so the OK button cannot be controlled. How should I do it?
Thanks in advance.
# python script import adsk.core, adsk.fusion, traceback _commandId = 'ValidateInputs' _input1ID = 'Selectioninput1' _input2ID = 'Selectioninput2' _handlers = [] _app = None _ui = None class CommandDestroyHandler(adsk.core.CommandEventHandler): def __init__(self): super().__init__() def notify(self, args): try: adsk.terminate() except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) class ValidateInputHandler(adsk.core.ValidateInputsEventHandler): def __init__(self): super().__init__() def notify(self, args): try: eventArgs = adsk.core.ValidateInputsEventArgs.cast(args) inputs = args.inputs i1 :adsk.core.SelectionCommandInput = inputs.itemById(_input1ID) i2 :adsk.core.SelectionCommandInput = inputs.itemById(_input2ID) if i1.selectionCount > 0 and i2.selectionCount > 0: eventArgs.areInputsValid = True else: eventArgs.areInputsValid = False _ui.messageBox('call ValidateInputs') except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler): def __init__(self): super().__init__() def notify(self, args): try: cmd = args.command onDestroy = CommandDestroyHandler() cmd.destroy.add(onDestroy) _handlers.append(onDestroy) onValidateInput = ValidateInputHandler() cmd.validateInputs.add(onValidateInput) _handlers.append(onValidateInput) inputs = cmd.commandInputs i1 = inputs.addSelectionInput(_input1ID, _input1ID, _input1ID) i1.setSelectionLimits(1,1) i2 = inputs.addSelectionInput(_input2ID, _input2ID, _input2ID) i2.setSelectionLimits(1,1) except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc())) def run(context): try: global _app, _ui _app = adsk.core.Application.get() _ui = _app.userInterface cmdDefs = _ui.commandDefinitions cmdDef = cmdDefs.itemById(_commandId) if cmdDef: cmdDef.deleteMe() cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId) onCmdCreated = CommandCreatedHandler() cmdDef.commandCreated.add(onCmdCreated) _handlers.append(onCmdCreated) cmdDef.execute() adsk.autoTerminate(False) except: if _ui: _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
Solved! Go to Solution.
Link copied