Unable to get command dialoge boxes to appear...

Unable to get command dialoge boxes to appear...

toffypops
Contributor Contributor
407 Views
5 Replies
Message 1 of 6

Unable to get command dialoge boxes to appear...

toffypops
Contributor
Contributor

Hello. 

I am first of all not a programmer , but more of a script kiddie, i can read code and understand it mostly but do not know how to troubleshoot it well, so, Copilot AI...

 

I tried to make some add-ins but i always fail to generate the command dialogue windows. 

 

In the below case, i have 

1. Created a .py file and .manifest file

2. Use the create button to generate the folder in the addins folder for fusion 360. 

3. I copy the files over to the addin folder and overwrite the default ones. 

4. i run the script, nothing pops up. I want to figure out how to make the command dialoge boxes appear. 

No errors, everything appear to launch, it is almost like they appear offscreen and is inaccessible. 

 

I am on the free version of fusion. 

SimpleCommandDialogAddIn.py

 

import adsk.core, adsk.fusion, traceback

# Global variables to keep references to event handlers
handlers = []

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        # Debug: Notify that the add-in is starting
        ui.messageBox('Add-in is starting...')

        # Create a command definition
        cmd_def = ui.commandDefinitions.addButtonDefinition(
            'SimpleCommandDialog',  # Unique ID for the command
            'Simple Command Dialog',  # Display name of the command
            'A simple test for command dialogs.',  # Description of the command
            ''  # No icon
        )
        cmd_def.commandCreated.add(CommandCreatedHandler())
        handlers.append(CommandCreatedHandler())

        # Debug: Notify that the command definition was created
        ui.messageBox('Command definition created.')

        # Execute the command
        cmd_def.execute()

        # Debug: Notify that the command was executed
        ui.messageBox('Command executed.')

        # Keep the command definition alive
        adsk.autoTerminate(False)

    except Exception as e:
        if ui:
            ui.messageBox('Failed to run add-in:\n{}'.format(traceback.format_exc()))

def stop(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface

        # Remove the command definition
        cmd_def = ui.commandDefinitions.itemById('SimpleCommandDialog')
        if cmd_def:
            cmd_def.deleteMe()

        ui.messageBox('Add-in stopped.')

    except Exception as e:
        if ui:
            ui.messageBox('Failed to stop add-in:\n{}'.format(traceback.format_exc()))

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args):
        try:
            app = adsk.core.Application.get()
            ui = app.userInterface

            # Debug: Notify that the command dialog is being created
            ui.messageBox('Command dialog is being created.')

            # Get the command inputs
            cmd = args.command
            inputs = cmd.commandInputs

            # Add a simple text box input
            inputs.addTextBoxCommandInput(
                'textBox',  # Unique ID for the input
                'Enter Text',  # Label for the input
                '',  # Default value
                1,  # Number of rows
                False  # Multiline (False = single line)
            )

            # Debug: Notify that the dialog was created
            ui.messageBox('Command dialog created successfully.')

        except Exception as e:
            if ui:
                ui.messageBox('Failed to create command dialog:\n{}'.format(traceback.format_exc()))

 

Manifest file: 
SimpleCommandDialogAddIn.manifest

{
    "id": "SimpleCommandDialogAddIn",
    "name": "Simple Command Dialog Add-In",
    "description": "A simple add-in to test command dialogs.",
    "version": "1.0.0",
    "author": "Your Name",
    "company": "Your Company",
    "supportedProducts": ["Fusion360"],
    "minVersion": "2.0.0",
    "maxVersion": "",
    "parameters": {}
}


Both of these rests inside 
AppData\Roaming\Autodesk\Autodesk Fusion 360\API\AddIns\SimpleCommandDialogAddIn

after i created the addin folder with fusion. 

0 Likes
408 Views
5 Replies
Replies (5)
Message 2 of 6

BrianEkins
Mentor
Mentor

I've attached a modified version of your program. There were several problems with it. What you are trying to do is explained in the reference manual. When looking through that topic, you'll want to look for the sample of a Script demonstrating a command. That's mostly what you had, not an add-in. I changed everything in the script to reflect that, but I forgot to rename the files. It doesn't matter what the name is, but just so you're aware.

 

https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-3922697A-7BF1-4799-9A5B-C8539DF57051

 

What you've run into is a common problem when using AI to create a program for Fusion. It's gets it 90-95% correct, but then you need to be an expert to debug and fix what it got wrong. The incorrect parts typically aren't very obvious because the AI will hallucinate and use functions that don't exist, so it looks good if you don't know the API in detail.

 

 

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
0 Likes
Message 3 of 6

toffypops
Contributor
Contributor

The script i tried to make suffered from similar problems, i just never got the windows to show, so i had the AI help me generate what I thought was a simple script to just open a Command Dialog window in fusion sketch environment, just to try and troubleshoot it. 

Thanks so much for helping me. 🙂

 

 

0 Likes
Message 4 of 6

toffypops
Contributor
Contributor

I have had time to review the script you made, and first thing at glance is that yours seems to be more logically structured, with improved references, from what i can understand. 

And some things were right out missing from the AI-generated script. Looking forward to get home to test this 🙂 

 

Again thanks so much for the help. Really appreciate it. 

0 Likes
Message 5 of 6

toffypops
Contributor
Contributor

.

0 Likes
Message 6 of 6

toffypops
Contributor
Contributor

I got a lot further, but i have a particular problem now. in my script i am trying to select 2 chained splines, but i cannot get the OK button to activate when i have selected 2 or more entities. i have tried various types of handlers to try and activate it, even tried different ways to call the splines or check the subtypes without luck. 

 

Here is a sample script that just opens a window, and a selection box, and then i can select 2 splines and try to accept the results. 

The example script does not really do anything, i just struggle getting it to trigger the OK button . 

 

The real script i made a few functions i managed to work in "preview" but i cannot get the OK command to activate to accept the results. 

Sorry to trouble you again, but was hoping the example script might shed light on why it is not able to trigger the OK button


And yes, i know it's AI, but it has helped me make a lot of progress i otherwise could not achieve. 

 

import adsk.core, adsk.fusion, traceback

handlers = []
app = adsk.core.Application.get()
ui = app.userInterface

def run(context):
try:
cmd_def = ui.commandDefinitions.addButtonDefinition(
'MinimalSelectionCommand',
'Minimal Spline Selector',
'Select two or more sketch splines to enable OK.',
''
)

panel = ui.allToolbarPanels.itemById('SketchCreatePanel')
if panel:
if not panel.controls.itemById('MinimalSelectionCommand'):
panel.controls.addCommand(cmd_def)

cmdCreated = MinimalCommandCreatedHandler()
cmd_def.commandCreated.add(cmdCreated)
handlers.append(cmdCreated)

adsk.autoTerminate(False)
except Exception as e:
ui.messageBox('Failed to run script:\n{}'.format(traceback.format_exc()))

def stop(context):
try:
panel = ui.allToolbarPanels.itemById('SketchCreatePanel')
if panel:
control = panel.controls.itemById('MinimalSelectionCommand')
if control:
control.deleteMe()
cmd_def = ui.commandDefinitions.itemById('MinimalSelectionCommand')
if cmd_def:
cmd_def.deleteMe()
except Exception as e:
ui.messageBox('Failed to stop script:\n{}'.format(traceback.format_exc()))

class MinimalCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
cmd = args.command
inputs = cmd.commandInputs

# Add selection input directly to the dialog (not in a tab)
sel_input = inputs.addSelectionInput(
'splineSel', 'Splines', 'Select two or more sketch splines.'
)
sel_input.addSelectionFilter('SketchCurves')
sel_input.setSelectionLimits(2, 0)

# Register handlers
onValidateInputs = MinimalValidateInputsHandler()
cmd.validateInputs.add(onValidateInputs)
handlers.append(onValidateInputs)

onInputChanged = MinimalInputChangedHandler()
cmd.inputChanged.add(onInputChanged)
handlers.append(onInputChanged)
except Exception as e:
ui.messageBox('Failed to create command dialog:\n{}'.format(traceback.format_exc()))

class MinimalValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
inputs = args.firingEvent.sender.commandInputs
sel_input = inputs.itemById('splineSel')
valid = False
if sel_input and sel_input.selectionCount >= 2:
# Check that all selected are splines
valid = True
for i in range(sel_input.selectionCount):
entity = sel_input.selection(i).entity
if entity.classType() not in [
'adsk.fusion.SketchFittedSpline',
'adsk.fusion.SketchControlPointSpline'
]:
valid = False
break
args.areInputsValid = valid
except Exception as e:
ui.messageBox('Failed to validate inputs:\n{}'.format(traceback.format_exc()))
args.areInputsValid = False

class MinimalInputChangedHandler(adsk.core.InputChangedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
cmd = args.firingEvent.sender
cmd.validateInputs()
except:
pass

 

 

 

0 Likes