Community
Fusion API and Scripts
Got a new add-in to share? Need something specialized to be scripted? Ask questions or share what you’ve discovered with the community.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to hide value input on start of command?

5 REPLIES 5
SOLVED
Reply
Message 1 of 6
Six1Seven1
470 Views, 5 Replies

How to hide value input on start of command?

Hi,

 

I am trying to hide my value input via the inputchangedevent handler, but it is not working correctly. When opening the addin dialogue, the "hidden" value input is VISIBLE. And i want it not visible unless my boolean value is TRUE.

 

Until the user click the button, then it will show up. Otherwise, it will stay hidden. 

 

Any way I configure the code, this does not work. Its always visible from the start. It will hide when I click it, sometimes have to click TWICE.

 

Creating the value input:

 

fillet_cb = inputs.addBoolValueInput('fillet_cb','Add Corner Fillets', False,'./Resources/Image Input/Fillets', False)

 

 

Input Changed Handler:

 

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:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))	

 

Regardless of changing the visibility to false and alternating the input command "initial value" , no configuration works. Button still visible on start of addin.

 

 

Thank you!

5 REPLIES 5
Message 2 of 6
marshaltu
in reply to: Six1Seven1

Hello,

 

You may have to give initial value "True" when create "fillet_cb". It meant you intend to show "fillet_in" command input by default. Otherwise you should hide "fillet_in" right away after it is created.

 

fillet_cb = inputs.addBoolValueInput('fillet_cb','Add Corner Fillets', False,'', True)

Thanks,

Marshal



Marshal Tu
Fusion 360 Developer
Autodesk, Inc.

Message 3 of 6
Six1Seven1
in reply to: marshaltu

Marshal,

 

Like I said, nothing works correctly. I have changed the initial value and the visibility logic over and over and the result is nearly the same. No hiding. This may be a bug.

 

But see my code 

 

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()
        
            # 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', False,'./Resources/Image Input/Fillets', True)
            fillet_in = inputs.addValueInput('fillet_in','Fillet Radius','',adsk.core.ValueInput.createByReal(0))
            
            
            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 = False
                else:
                    fillet_in.isVisible = True

        except:
            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()))	

 

 

Message 4 of 6
ekinsb
in reply to: Six1Seven1

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()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 5 of 6
Six1Seven1
in reply to: ekinsb

Ok Brian allow me to check this.

 

Thank you for your time,

 

Ill report back

Message 6 of 6
Six1Seven1
in reply to: ekinsb

Brian,

 

It worked!  What worked was setting the .isVisible property to FALSE. Any other solution did not work. Thank you for your time. I appreciate it.

 

 

 

Regards

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report