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 update the Fusion 360 API

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
mtBXZKP
267 Views, 3 Replies

How to update the Fusion 360 API

Hi everyone,

 

Is the Fusion 360 app API updated automatically?

 

I'm writing a python add-in, and I want to use some new properties introduced in the November 2022 update - however they do not seem to be included in core.py (the API).

 

I'm specifically interested in the maximum/minimumValue properties for ValueCommandInput's.

 

Best Regards, 

Mathias Thor 

Tags (1)
3 REPLIES 3
Message 2 of 4
kandennti
in reply to: mtBXZKP

Hi @mtBXZKP .

 

API will be updated together.

 

Here is a sample using maximum/minimumValue.

# Fusion360API Python script

import traceback
import adsk
import adsk.core as core

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

CMD_INFO = {
    'id': 'kantoku_test',
    'name': 'test',
    'tooltip': 'test'
}

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

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

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

            valueIpt: core.ValueCommandInput = inputs.addValueInput(
                'valueIptId',
                '1mm - 3mm',
                'mm',
                core.ValueInput.createByReal(0.2)
            )
            valueIpt.minimumValue = 0.1
            valueIpt.maximumValue = 0.3

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


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

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


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

        cmdDef: core.CommandDefinition = _ui.commandDefinitions.itemById(
            CMD_INFO['id']
        )

        if not cmdDef:
            cmdDef = _ui.commandDefinitions.addButtonDefinition(
                CMD_INFO['id'],
                CMD_INFO['name'],
                CMD_INFO['tooltip']
            )

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

 

The valid range is set to 1-3mm, so if the value is out of the range, the text will be red and the OK button will be grayed out.

1.png

Message 3 of 4
mtBXZKP
in reply to: kandennti

Hi @kandennti 

 

Thanks for your detailed answer!

Somehow my Fusion 360 was not up to date...

 

Best Regards, 

Mathias Thor

Message 4 of 4
kandennti
in reply to: mtBXZKP

@mtBXZKP .

 

Last year there was a version where "LiveUpdate" didn't work.

At that time, I had to manually re-install the Fusion360 overwrite to bring the version up to date.

The latest version now is ver 2.0.15050.

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

Post to forums