Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.

addFloatSliderCommandInput Slider Increment

ebunn3
Advocate

addFloatSliderCommandInput Slider Increment

ebunn3
Advocate
Advocate

I see that there is a way to set the spinStep for a slider but there does not appear to be a way to set something similar for the slider itself.  Is there a way to set the sensitivity of the slider so it increments a lessor amount when using the slider.  SpinStep does not appear to affect this slider behavior at all.

 

Eric

 

ebunn3_0-1650299972284.png

 

0 Likes
Reply
398 Views
3 Replies
Replies (3)

kandennti
Mentor
Mentor

Hi @ebunn3 .

 

I tried it too.
It changed the properties but did not change the behavior.

# Fusion360API Python script

import traceback
import adsk.fusion
import adsk.core

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

_sliderIpt: adsk.core.FloatSliderCommandInput = None
_dropDownIpt: adsk.core.DropDownCommandInput = None

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
            inputs: adsk.core.CommandInputs = cmd.commandInputs

            global _sliderIpt
            _sliderIpt = inputs.addFloatSliderCommandInput(
                'sliderIptId',
                'Slider',
                'mm',
                0.0,
                100.0,
                False
            )
            unitMgr: adsk.core.UnitsManager = _app.activeProduct.unitsManager
            _sliderIpt.spinStep = unitMgr.convert(1, unitMgr.defaultLengthUnits, unitMgr.internalUnits)

            global _dropDownIpt
            _dropDownIpt = inputs.addDropDownCommandInput(
                'dropDownIptId',
                'Slider Step',
                adsk.core.DropDownStyles.TextListDropDownStyle
            )
            ddItems = _dropDownIpt.listItems
            ddItems.add('1', True, '')
            ddItems.add('5', False, '')
            ddItems.add('10', False, '')
            ddItems.add('20', False, '')

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

            onStepChanged = StepChangedHandler(_dropDownIpt)
            cmd.inputChanged.add(onStepChanged)
            _handlers.append(onStepChanged)


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


class StepChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self, ddIpt: adsk.core.DropDownCommandInput):
        super().__init__()
        self.input = ddIpt

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

        if self.input != args.input:
            return

        global _dropDownIpt, _sliderIpt
        step = float(_dropDownIpt.selectedItem.name)

        _sliderIpt.spinStep = step

        global _app
        _app.log(f'Slider SpinStep:{_sliderIpt.spinStep}')


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

BrianEkins
Mentor
Mentor

I suspect this isn't supported internally by the float slider. When I use some Fusion commands that have float sliders their values aren't nice even values. I'm guessing that Fusion determines the increment based on the number of pixels the slider currently spans and that's what you get.

---------------------------------------------------------------
Brian Ekins
Inventor and Fusion 360 API Expert
Website/Blog: https://EkinsSolutions.com
1 Like

ebunn3
Advocate
Advocate

Thanks all for the support.  

Eric

0 Likes