Custom Feature: Dialog seems buggy
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to make the inputs for my feature, and make it interactive.
I've got two selection inputs
- one for a occurrence
- one for multiple faces
then there is two dropdown inputs.
the first thing i'm noticing, is as soon as i'm picking an occurrence, i'm able to execute the command (click the ok button)
which shouldn't be possible according to command_validate_inputs() since the selection input for "Selection_Faces"
isn't populated.
the next thing is that i want to hide the selected occurrence when selected, which i'm able to, but that doesn't populate "Selection_Body".
i belive it's because command_input_changed() is called before it is visible for the user. but it kinda seems like it is actually saved in the input, but not shown, because command_validate_input() completes.
am i doing something wrong?
selected_occurrence: adsk.fusion.Occurrence = None
def command_created(args: adsk.core.CommandCreatedEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Command Created Event')
# Selections
selectionBody = inputs.addSelectionInput("Selection_Body", "Surface Body", "Select affected body")
selectionBody.addSelectionFilter("Occurrences")
selectionBody.setSelectionLimits(1, 1)
selectionEdges = inputs.addSelectionInput("Selection_Faces", "Edges", "Select edges")
selectionEdges.addSelectionFilter("Faces")
selectionEdges.setSelectionLimits(1, 0)
# Fixing dropdown
DropDownOne = inputs.addDropDownCommandInput("DropDown1", "Select Item", 0)
DropDownOne.listItems.add("None", False)
DropDownOne.listItems.add("Dropdown 1 Item 1", True)
# Dowel dropdown
DropDownTwo = inputs.addDropDownCommandInput("DropDown2", "Select Item", 0)
DropDownTwo.listItems.add("None", False)
DropDownTwo.listItems.add("Dropdown 2 Item 1", True)
# TODO Connect to the events that are needed by this command.
futil.add_handler(args.command.validateInputs, command_validate_input, local_handlers=local_handlers)
futil.add_handler(args.command.executePreview, command_preview, local_handlers=local_handlers)
futil.add_handler(args.command.inputChanged, command_input_changed, local_handlers=local_handlers)
futil.add_handler(args.command.execute, command_execute, local_handlers=local_handlers)
futil.add_handler(args.command.destroy, command_destroy, local_handlers=local_handlers)
def command_execute(args: adsk.core.CommandEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Command Execute Event')
global selected_occurrence
selected_occurrence.isLightBulbOn = True
selected_occurrence = None
# Get a reference to your command's inputs.
inputs = args.command.commandInputs
def command_preview(args: adsk.core.CommandEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Command Preview Event')
inputs = args.command.commandInputs
def command_input_changed(args: adsk.core.InputChangedEventArgs):
changed_input = args.input
inputs = args.inputs
if changed_input.id == "Selection_Body":
selected_body: adsk.core.SelectionCommandInput = inputs.itemById("Selection_Body")
selected_body_occurrence: adsk.fusion.Occurrence = selected_body.selection(0).entity
selected_body_occurrence.isLightBulbOn = False
# General logging for debug.
futil.log(f'{CMD_NAME} Input Changed Event fired from a change to {changed_input.id}')
def command_validate_input(args: adsk.core.ValidateInputsEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Validate Input Event')
inputs = args.inputs
args.areInputsValid = False
# Verify the validity of the input values. This controls if the OK button is enabled or not.
selectedBody: adsk.core.SelectionCommandInput = inputs.itemById("Selection_Body")
if selectedBody.selectionCount == 0:
return
selectedFaces: adsk.core.SelectionCommandInput = inputs.itemById("Selection_Faces")
if selectedFaces.selectionCount == 0:
return
dropDownOneValue: adsk.core.DropDownCommandInput = inputs.itemById("DropDown1")
dropDownTwoValue: adsk.core.DropDownCommandInput = inputs.itemById("DropDown2")
if dropDownOneValue.selectedItem.name == dropDownTwoValue.selectedItem.name:
return
args.areInputsValid = True
def command_destroy(args: adsk.core.CommandEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Command Destroy Event')
global local_handlers
local_handlers = []
Thanks in advance