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: 

Change the 'caption' of an IntegerSliderCommandInput

2 REPLIES 2
SOLVED
Reply
Message 1 of 3
MarkBrouwersY48AV
131 Views, 2 Replies

Change the 'caption' of an IntegerSliderCommandInput

Hi,

 

I want to change the caption of an IntegerSliderCommandInput

MarkBrouwersY48AV_1-1690981506048.png

I want to add the name of the selected value in my combobox to my IntegerSliderCommandInput text.

So in this case I would like to see 'Selected Parameter value Diameter'.

I tried the function IntegerSliderCommandInput.settext, but this does not work. Changing the name property of this IntegerSliderCommandInput is not allowed.

 

How can this be done ?

 

Cheers,

Mark

 

 

2 REPLIES 2
Message 2 of 3

Hi @MarkBrouwersY48AV -San.

 

Perhaps that is not possible.
It seems that the events of the Command object have a role to play, not simply a different timing when they occur.

 

It seems that it is only within the commandCreated event handler that the name property of IntegerSliderCommandInput can be changed, as in this case.

 

As an alternative, I created a sample.
The only way to do this is to prepare the IntegerSliderCommandInput corresponding to the ComboBox (DropDownCommandInput) in advance and show/hide it.

# 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'
}

_dDownIpt: core.DropDownCommandInput = None
_sliderA: core.IntegerSliderCommandInput = None
_sliderB: core.IntegerSliderCommandInput = None
_sliderC: core.IntegerSliderCommandInput = None


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)

            onInputChanged = MyInputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            _handlers.append(onInputChanged)

            global _dDownIpt
            _dDownIpt = inputs.addDropDownCommandInput(
                "_dDownIptId",
                "Choice",
                core.DropDownStyles.TextListDropDownStyle
            )
            dDownItems: core.ListItems = _dDownIpt.listItems
            dDownItems.add("A", True)
            dDownItems.add("B", False)
            dDownItems.add("C", False)

            global _sliderA
            _sliderA = inputs.addIntegerSliderCommandInput(
                "_sliderAid",
                "A",
                0,
                10,
            )

            global _sliderB
            _sliderB = inputs.addIntegerSliderCommandInput(
                "_sliderBid",
                "B",
                0,
                10,
            )
            _sliderB.isVisible = False

            global _sliderC
            _sliderC = inputs.addIntegerSliderCommandInput(
                "_sliderCid",
                "C",
                0,
                10,
            )
            _sliderC.isVisible = False

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


class MyInputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args: core.InputChangedEventArgs):
        global _dDownIpt

        if args.input != _dDownIpt: return

        global _sliderA, _sliderB, _sliderC
        selectName = _dDownIpt.selectedItem.name
        if selectName == "A":
            _sliderA.isVisible = True
            _sliderB.isVisible = _sliderC.isVisible = False
        elif selectName == "B":
            _sliderB.isVisible = True
            _sliderA.isVisible = _sliderC.isVisible = False
        elif selectName == "C":
            _sliderC.isVisible = True
            _sliderA.isVisible = _sliderB.isVisible = False


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


If you want to create more flexible dialogs, we recommend using Palette or BrowserCommandInputs.
However, knowledge of html and javascript is required.

Message 3 of 3

Hi Makoto,

 

Thanks again for your reply and suggesting a solution.  understand what you're doing and this works for me to some extend. 

Kudo's for you !

 

Cheers,

Mark

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