Here's a slight variation of your add-in that seems to be working as expected. The main thing I did to address your question is that I set the isVisible property of the ValueCommandInput to False right after it's created. That stops it from being displayed when the dialog first appears. That was the main problem. I also fixed a couple of issues where you defining the ui variable so it was failing when trying to display some errors (because I didn't have the resource files). Another change that I made that you might want to change back is that I changed one of the arguments when creating the bool value input to be a check box. Because it has an image assigned to it, it still looks like a button but now it behaves like a check box in that it has two states, pressed and unpressed, which I think is what you might want. A typical button doesn't really have states but is just used to notify you want it's clicked.
import adsk.core, adsk.fusion, adsk.cam, traceback
# Global list to keep all event handlers in scope.
# This is only needed with Python.
handlers = []
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
# Get the CommandDefinitions collection.
cmdDefs = ui.commandDefinitions
# Create a button command definition.
buttonSample = cmdDefs.addButtonDefinition('MainButton','Plate Generator', 'An Add-in which generates a solid rectangle and applies holes or slots equidistant from part center.','./Resources/Main Icons')
# Connect to the command created event.
MainButtonEvent = SampleCommandCreatedEventHandler()
buttonSample.commandCreated.add(MainButtonEvent)
handlers.append(MainButtonEvent)
# Get the ADD-INS panel in the model workspace.
addInsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
# Add the button to the bottom of the panel.
buttonControl = addInsPanel.controls.addCommand(buttonSample)
buttonControl.isPromoted = True
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the commandCreated event.
class SampleCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
app = adsk.core.Application.get()
ui = app.userInterface
# Get the command
cmd = eventArgs.command
cmd.okButtonText = ("Generate") #text in "OK" button
# Get the CommandInputs collection to create new command inputs.
inputs = cmd.commandInputs
#Add image input
imageinput1 = inputs.addImageCommandInput('imageinput1','Diagram:','./Resources/Image Input/Diagram/diagram.png')
# Create the value inputs
length_in = inputs.addValueInput('length_in', 'Length','', adsk.core.ValueInput.createByReal(3))
width_in = inputs.addValueInput('width_in','Width','',adsk.core.ValueInput.createByReal(2))
thick_in = inputs.addValueInput('thick_in','Thickness','',adsk.core.ValueInput.createByReal(1))
hole_cb = inputs.addBoolValueInput('hole_cb','Add Hole Pattern', True,'', True)
hole_dia = inputs.addValueInput('hole_dia','Hole Diameter','',adsk.core.ValueInput.createByReal(0))
hole_spcX = inputs.addValueInput('hole_spcX','Hole Spacing in X','',adsk.core.ValueInput.createByReal(0))
hole_spcY = inputs.addValueInput('hole_spcY','Hole Spacing in Y','',adsk.core.ValueInput.createByReal(0))
fillet_cb = inputs.addBoolValueInput('fillet_cb','Add Corner Fillets', True,'./Resources/Image Input/Fillets', False)
fillet_in = inputs.addValueInput('fillet_in','Fillet Radius','',adsk.core.ValueInput.createByReal(0))
fillet_in.isVisible = False
qty = inputs.addDropDownCommandInput('qty','Quantity',1)
list_items1 = qty.listItems
list_items1.add('2',True,'')
list_items1.add('4',False,'')
inputChanged = inputChangedEvent()
cmd.inputChanged.add(inputChanged)
handlers.append(inputChanged)
onExecute = SampleCommandExecuteHandler()
cmd.execute.add(onExecute)
handlers.append(onExecute)
# onExecutePreview = MyExecutePreviewHandler()
# cmd.executePreview.add(onExecutePreview)
# handlers.append(onExecutePreview)
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
# Event handler for the execute event.
class SampleCommandExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
eventArgs = adsk.core.CommandEventArgs.cast(args)
# Code to react to the event.
app = adsk.core.Application.get()
ui = app.userInterface
ui.messageBox('In command execute event handler.')
eventArgs = adsk.core.CommandEventArgs.cast(args)
# Get the values from the command inputs.
inputs = eventArgs.command.commandInputs
length = inputs.itemById('length_in').value
width = inputs.itemById('width_in').value
thickness = inputs.itemById('thick_in').value
fillet = inputs.itemById('fillet_in').value
filletcb = inputs.itemById('fillet_cb').value
hole_dia = inputs.itemById('hole_dia').value
hole_spcX = inputs.itemById('hole_spcX').value
hole_spcY = inputs.itemById('hole_spcY').value
holecb = inputs.itemById('hole_cb').value
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
class inputChangedEvent(adsk.core.InputChangedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
eventArgs = adsk.core.InputChangedEventArgs.cast(args)
changedInput = eventArgs.input
fillet_in = None
if changedInput.id == 'fillet_cb':
inputs = eventArgs.firingEvent.sender.commandInputs
fillet_in = inputs.itemById('fillet_in')
# Change the visibility of the scale value input.
if fillet_in:
if changedInput.value == True:
fillet_in.isVisible = True
else:
fillet_in.isVisible = False
except:
app = adsk.core.Application.get()
ui = app.userInterface
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
def stop(context):
try:
app = adsk.core.Application.get()
ui = app.userInterface
#Delete Button Def
buttonSample = ui.commandDefinitions.itemById('MainButton')
if buttonSample:
buttonSample.deleteMe()
#Delete Button Control
addinsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
cntrl = addinsPanel.controls.itemById('MainButton')
if cntrl:
cntrl.deleteMe()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))