Edit field for valueCommandInput in command dialog box not showing up

Edit field for valueCommandInput in command dialog box not showing up

Anonymous
Not applicable
488 Views
2 Replies
Message 1 of 3

Edit field for valueCommandInput in command dialog box not showing up

Anonymous
Not applicable

Hello,

 

I assume I'm missing something and it's not a bug since it doesn't seem like others are having this issue. 

 

This is the code excerpt from my CommandCreated handler:

# Add value inputs to get the X, Y, and Z values for start and end point.
            startXValInput = inputs.addValueInput('startXValInput', 'Start X Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(100))
            startYValInput = inputs.addValueInput('startYValInput', 'Start Y Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(10))
            startZValInput = inputs.addValueInput('startZValInput', 'Start Z Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(0))
            endXValInput = inputs.addValueInput('endXValInput', 'End X Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(10))
            endYValInput = inputs.addValueInput('endYValInput', 'End Y Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(0))
            endZValInput = inputs.addValueInput('endZValInput', 'End Z Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(99))
    

the add-in yields a dialog box that looks like this:

Screen Shot 2019-07-23 at 8.39.04 PM.png

with no field to type in number values like this (from the example SpurGear add-in):Screen Shot 2019-07-24 at 2.20.00 AM.png

 

I went over some example add-ins where it functioned correctly and can't seem to figure out what I'm missing. 

 

Thank you for helping out a Fusion 360 API newbie!

 

Here's the code from my entire add-in for reference:

#Author-MD
#Description- Fairly simple. makes pipes.

import adsk.core, adsk.fusion, adsk.cam, traceback

# Global variables to keep everything in scope
handlers = []
app = adsk.core.Application.get()
ui = app.userInterface
design = adsk.fusion.Design.cast(None)
pointsData = []  # A list of lists containing the coordinate (Point3D) and Name of each point.
isParametric = True
startXValInput = adsk.core.ValueCommandInput.cast(None)
startYValInput = adsk.core.ValueCommandInput.cast(None)
startZValInput = adsk.core.ValueCommandInput.cast(None)
endXValInput = adsk.core.ValueCommandInput.cast(None)
endYValInput = adsk.core.ValueCommandInput.cast(None)
endZValInput = adsk.core.ValueCommandInput.cast(None)
selectStartPoint = adsk.core.BoolValueCommandInput.cast(None)


# Event handler for the commandCreated event.
class PipeCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            global startXValInput, startYValInput, startZValInput, endXValInput, endYValInput, endZValInput, selectStartPoint
            eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
            cmd = eventArgs.command
            inputs = cmd.commandInputs
            
            # Connect handler for mouseEvent 
            onClick = CommandMouseClickHandler()
            cmd.mouseClick.add(onClick)
            handlers.append(onClick)
            
            #Connect handler to inputChanged event
            onInputChanged = CommandInputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            handlers.append(onInputChanged)
            
            # Connect handler to executePreview event.       
            onExecutePreview = ExecutePreviewHandler()
            cmd.executePreview.add(onExecutePreview)
            handlers.append(onExecutePreview)    
            
            # Connect handler to the execute event.
            onExecute = CommandExecuteHandler()
            cmd.execute.add(onExecute)
            handlers.append(onExecute)
            
                
            # Add value inputs to get the X, Y, and Z values for start and end point.
            startXValInput = inputs.addValueInput('startXValInput', 'Start X Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(100))
            startYValInput = inputs.addValueInput('startYValInput', 'Start Y Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(10))
            startZValInput = inputs.addValueInput('startZValInput', 'Start Z Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(0))
            endXValInput = inputs.addValueInput('endXValInput', 'End X Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(10))
            endYValInput = inputs.addValueInput('endYValInput', 'End Y Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(0))
            endZValInput = inputs.addValueInput('endZValInput', 'End Z Position', design.unitsManager.defaultLengthUnits, adsk.core.ValueInput.createByReal(99))
    
            # Check box to toggle between start and end point selection
            selectStartPoint = inputs.addBoolValueInput('selectStartPoint', 'Check to select start point, uncheck to select end point', True)    
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
            
       
# Event handler for mouse click event
class CommandMouseClickHandler(adsk.core.MouseEventHandler):
    def __init__(self):
        super().__init__()
    
    def notify(self, args):
        try:
            global startXValInput, startYValInput, endXValInput, endYValInput
            eventArgs = adsk.core.MouseEventArgs.cast(args)
            
            # Change start point location
            if selectStartPoint:
                
                # Set the x and y value of the selected point equal to the mouse click's location
                ui.messageBox('Mouse posiiton: ' + str(eventArgs.position.x))
                ui.messageBox('Current x value: ' + str(startXValInput.value))
                startXValInput.value = eventArgs.position.x
                startYValInput.value = eventArgs.position.y
                
            # Change end point location
            else:
                # Set the x and y value of the selected point equal to the mouse click's location
                endXValInput.value = eventArgs.position.x
                endYValInput.value = eventArgs.position.y
            ui.messageBox('MOUSE CLICK CLASS NOT FINISHED YET')
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


# Event handler for the inputChanged event.
class CommandInputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
         try:
            ui.messageBox('INPUT CHANGED HANDLER CLASS NOT FINISHED YET')
         except:
             if ui:
                 ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
   
              
# Event handler for the executePreview event    
class ExecutePreviewHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            ui.messageBox('EXECUTE PREVIEW HANDLER CLASS NOT FINISHED YET')
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))          
                
                
# Event handler for the execute event.
class CommandExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            app = adsk.core.Application.get()
            ui  = app.userInterface
            eventArgs = adsk.core.CommandEventArgs.cast(args)
            
            # get command and load points
            inputs = eventArgs.command.commandInputs
            #createPoints(inputs)
            ui.messageBox('EXECUTE HANDLER CLASS NOT FINISHED YET')
        except:
            if ui:
                ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

    
def createPipe(startPoint, endPoint):
        ui.messageBox('In create pipe function')
        sketch = startPoint.parentSketch
        lines = sketch.sketchCurves.sketchLines
        lines.addByTwoPoints(startPoint, endPoint)


def run(context):
    try:
        # Get the CommandDefinitions collection.
        cmdDefs = ui.commandDefinitions
        
        # Create a button command definition.
        buttonDefinition = cmdDefs.addButtonDefinition('PipeButtonId', 
                                                   'Pipe Route', 
                                                   'Create a pipe route between two points. \n\nTo use. Create a new sketch or open an existing one. Create two points. Run the Create Pipe script and select start and end point.',
                                                   'resources')
        
        # Get the ADD-INS panel in the model workspace. 
        addInsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
        
        # Add the button to the bottom of the panel.
        buttonCommand = addInsPanel.controls.addCommand(buttonDefinition)
        buttonCommand.isPromoted = True
        buttonCommand.isPromotedByDefault = True
        
        # Connect to the command created event.
        pipeCommandCreated = PipeCommandCreatedEventHandler()
        buttonDefinition.commandCreated.add(pipeCommandCreated)
        handlers.append(pipeCommandCreated)
        
        # Check to see if this is a parametric or direct-edit model.
        global design, isParametric
        design = adsk.fusion.Design.cast(app.activeProduct)
        if design:
            if design.designType == adsk.fusion.DesignTypes.ParametricDesignType:
                isParametric = True
            else:
                isParametric = False    
        else:
            ui.messageBox('You must be in a modeling related workspace.')
            return False
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
            
            
def stop(context):
    try:
        # Clean up the UI.
        cmdDef = ui.commandDefinitions.itemById('PipeButtonId')
        if cmdDef:
            cmdDef.deleteMe()
            
        addinsPanel = ui.allToolbarPanels.itemById('SolidScriptsAddinsPanel')
        cntrl = addinsPanel.controls.itemById('PipeButtonId')
        if cntrl:
            cntrl.deleteMe()
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))	
            
 
0 Likes
489 Views
2 Replies
Replies (2)
Message 2 of 3

goyals
Autodesk
Autodesk

       # Connect handler for mouseEvent 

            onClick = CommandMouseClickHandler()

            cmd.mouseClick.add(onClick)

            handlers.append(onClick)

            

            #Connect handler to inputChanged event

            onInputChanged = CommandInputChangedHandler()

            cmd.inputChanged.add(onInputChanged)

            handlers.append(onInputChanged)

            

            # Connect handler to executePreview event.       

            onExecutePreview = ExecutePreviewHandler()

            cmd.executePreview.add(onExecutePreview)

            handlers.append(onExecutePreview)    

            

            # Connect handler to the execute event.

            onExecute = CommandExecuteHandler()

            cmd.execute.add(onExecute)

            handlers.append(onExecute)

 

If you move these registration of handlers at the end of notify function in PipeCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler), it will work. I need to investigate further why it is making difference but I hope it might help you to move further for now.



Shyam Goyal
Sr. Software Dev. Manager
Message 3 of 3

Anonymous
Not applicable

I realized the issue is actually that if the name of the value command is too long and the dialog box too small, the name can "push" the edit field outside the dialog box where it can't be viewed or edited.

0 Likes