how to use groupCommands ?

how to use groupCommands ?

mohammadkhader698
Participant Participant
507 Views
3 Replies
Message 1 of 4

how to use groupCommands ?

mohammadkhader698
Participant
Participant

I need to make userInterface to get Inputs from the  user then modify the design so I decide to use groupCommad but the problem is I cant understand the parameters for groupCommad  and  I don't know how to use it   

0 Likes
Accepted solutions (1)
508 Views
3 Replies
Replies (3)
Message 2 of 4

kandennti
Mentor
Mentor

Hi @mohammadkhader698 .

 

We made a simple sample.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

_app: adsk.core.Application = None
_ui: adsk.core.UserInterface = None
_handlers = []

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

    def notify(self, args: adsk.core.CommandCreatedEventArgs):
        adsk.core.Application.get().log(args.firingEvent.name)
        try:
            global _handlers
            cmd: adsk.core.Command = adsk.core.Command.cast(args.command)
            inputs: adsk.core.CommandInputs = cmd.commandInputs

            onDestroy = MyCommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onExecute = MyExecuteHandler()
            cmd.execute.add(onExecute)
            _handlers.append(onExecute)

            inputs.addTextBoxCommandInput(
                'txtOutIpt',
                'text',
                'Outside',
                1,
                True
            )

            # https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-38a0b5b9-9339-4c4e-b113-130877c99497
            grpIpt: adsk.core.GroupCommandInput = inputs.addGroupCommandInput(
                'grpIptId',
                'Group Input Test'
            )
            grpChildIpts: adsk.core.CommandInputs = grpIpt.children

            grpChildIpts.addTextBoxCommandInput(
                'txtInIpt',
                'text',
                'Inside',
                1,
                True
            )

        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


class MyExecuteHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: adsk.core.CommandEventArgs):
        adsk.core.Application.get().log(args.firingEvent.name)


class MyCommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()

    def notify(self, args: adsk.core.CommandEventArgs):
        adsk.core.Application.get().log(args.firingEvent.name)
        adsk.terminate()


def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDef: adsk.core.CommandDefinition = _ui.commandDefinitions.itemById(
            'test_cmd'
        )

        if not cmdDef:
            cmdDef = _ui.commandDefinitions.addButtonDefinition(
                'test_cmd',
                'Test',
                'Test'
            )

        global _handlers
        onCommandCreated = MyCommandCreatedHandler()
        cmdDef.commandCreated.add(onCommandCreated)
        _handlers.append(onCommandCreated)

        cmdDef.execute()

        adsk.autoTerminate(False)

    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))
0 Likes
Message 3 of 4

mohammadkhader698
Participant
Participant

thank you @kandennti  but honestly I don't know how to make command input , so what I need is to make script that get inputs from user then modify an exist design ,I have already a parametric design so I thought just I need the inputs from the user  so what is the best way to do the script  

0 Likes
Message 4 of 4

Jorge_Jaramillo
Collaborator
Collaborator
Accepted solution

hi @mohammadkhader698 

 

What you want require two parts:

 

1. To add the user interface to prompt for the information that is required.  This is done with the COMMANDS, which are the user interface controls in Fusion360.  Here you have a good example with many options: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-e5c4dbe8-ee48-11e4-9823-f8b156d7cd97 

 

2. Since you have a parametric design, then you need to update the values of your parameters with the user input.

Here you have an example of how to update a parameter value by code: https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-33127518-f20a-11e5-bab1-a0a8cd5c2c67

 

Hope this two examples help you in the implementation.

Keeping the API Reference Manual open while you develop is very handy.

 

Regards,

Jorge