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 use groupCommands ?

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
mohammadkhader698
112 Views, 3 Replies

how to use groupCommands ?

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   

3 REPLIES 3
Message 2 of 4

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()))
Message 3 of 4

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  

Message 4 of 4

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

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