- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to make an add-in that lets me enter data for one of several geometries. I'm starting with all the necessary inputs created but invisible, then when the user selects which type of geometry they want, I make those inputs visible (and re-hide the others just in case). This works fine.
The problem is that if I need to include a selectionInput for some of them, and it seems that any time any of them is left empty it kills my add-in. It dies before even getting to the command_execute function, so I can't put up a messageBox with any of the data to help debugging. I've confirmed it's the selection commands just by adding and removing commands until I get the errors again.
I'm not sure why everything is dying, so I'm not really sure how to fix it. First I tried enabling and disabling the inputs along with making them visible, but as they call out in the documentation that doesn't really work for selectionInputs. I also tried using the .deleteMe method to get rid of the ones I don't need, but that just crashes Fusion entirely.
Thanks for any help or insight here, I am at a loss at this point.
Here's the code that creates the input
def command_created(args: adsk.core.CommandCreatedEventArgs):
# General logging for debug.
futil.log(f'{CMD_NAME} Command Created Event')
# https://help.autodesk.com/view/fusion360/ENU/?contextId=CommandInputs
inputs = args.command.commandInputs
# Create text inputs for the component
selectionInput0 = inputs.addSelectionInput('component', 'Component', 'Select the component that contains this feature')
selectionInput0.addSelectionFilter('Occurrences')
selectionInput0.setSelectionLimits(1)
# Create a text input for the feature description
descriptionInput = inputs.addTextBoxCommandInput('description', 'Description', 'xy-plane 1', 1, False)
# Create dropdown input for feature type selection
typeInput = inputs.addDropDownCommandInput('type', 'Feature Type', adsk.core.DropDownStyles.TextListDropDownStyle)
typeList = ['plane', 'well']
types = typeInput.listItems
for t in typeList:
types.add(t, False)
# Create a selection for a plane surface
planeInput = inputs.addSelectionInput('plane', 'Plane', 'Select the plane that the feature will be created on')
planeInput.addSelectionFilter('Faces')
planeInput.addSelectionFilter('ConstructionPlanes')
planeInput.addSelectionFilter('Sketches')
planeInput.isVisible = False
# Create a selection for points
pointsInput = inputs.addSelectionInput('points', 'Points', 'Select the points that define the feature')
pointsInput.addSelectionFilter('SketchPoints')
pointsInput.addSelectionFilter('ConstructionPoints')
pointsInput.setSelectionLimits(0)
pointsInput.isVisible = False
# Create a selection for well base
wellInput = inputs.addSelectionInput('wellBase', 'Well Base', 'Select the base of the well')
wellInput.addSelectionFilter('Faces')
wellInput.addSelectionFilter('ConstructionPlanes')
wellInput.addSelectionFilter('Sketches')
wellInput.isVisible = False
# Create a value input for well diameter
diameterInput = inputs.addValueInput('wellDiameter', 'Well Diameter', 'mm', adsk.core.ValueInput.createByReal(0))
diameterInput.isVisible = False
# Create a value input for well depth
depthInput = inputs.addValueInput('wellDepth', 'Well Depth', 'mm', adsk.core.ValueInput.createByReal(0))
depthInput.isVisible = False
# TODO Connect to the events that are needed by this command.
futil.add_handler(args.command.execute, command_execute, local_handlers=local_handlers)
futil.add_handler(args.command.inputChanged, command_input_changed, local_handlers=local_handlers)
futil.add_handler(args.command.executePreview, command_preview, local_handlers=local_handlers)
futil.add_handler(args.command.validateInputs, command_validate_input, local_handlers=local_handlers)
futil.add_handler(args.command.destroy, command_destroy, local_handlers=local_handlers)
Here's the code that hides the unused commands:
def command_input_changed(args: adsk.core.InputChangedEventArgs):
inputs = args.inputs
cmdInput = args.input
type: adsk.core.DropDownCommandInput = inputs.itemById('type')
if cmdInput.id == 'type':
if type.selectedItem.name == 'plane':
inputs.itemById('plane').isVisible = True
inputs.itemById('points').isVisible = True
inputs.itemById('wellBase').isVisible = False
inputs.itemById('wellDiameter').isVisible = False
inputs.itemById('wellDepth').isVisible = False
elif type.selectedItem.name == 'well':
inputs.itemById('plane').isVisible = False
inputs.itemById('points').isVisible = False
inputs.itemById('wellBase').isVisible = True
inputs.itemById('wellDiameter').isVisible = True
inputs.itemById('wellDepth').isVisible = True
For now my command execute is very simple while I'm trying to debug this.
def command_execute(args: adsk.core.CommandEventArgs):
ui.messageBox("Feature Generator Started")
# General logging for debug.
futil.log(f'{CMD_NAME} Command Execute Event')
Solved! Go to Solution.