<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How do I set the initial value and also an updated value for a Python slider control? in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11110596#M6153</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10830800"&gt;@tim.collins29V9X&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After creating an instance, the valueOne property can be set.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-0f49349e-5ad6-4386-9d78-91da5387e82e" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-0f49349e-5ad6-4386-9d78-91da5387e82e&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# 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)

            sliderIpt: adsk.core.IntegerSliderCommandInput = inputs.addIntegerSliderCommandInput(
                'sliderId',
                'test',
                15,
                32,
                False
            )
            sliderIpt.valueOne = 22

        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


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()))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 17 Apr 2022 13:14:53 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2022-04-17T13:14:53Z</dc:date>
    <item>
      <title>How do I set the initial value and also an updated value for a Python slider control?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11109818#M6152</link>
      <description>&lt;P&gt;In my Python add-in I&amp;nbsp;have an integer value that can be between 15 and 32 and the initial value is 22.&amp;nbsp; I'd like to use a slider but it does not have an initial value.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;FONT face="courier new,courier"&gt; &amp;nbsp;def &lt;/FONT&gt;&lt;/SPAN&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;addIntegerSliderCommandInput&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;self&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;id&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;int&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;max&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;int&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;hasTwoSliders&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;bool&lt;/SPAN&gt;&lt;SPAN&gt;) -&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;IntegerSliderCommandInput&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;A spinner does have the initial value:&lt;BR /&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&amp;nbsp; &amp;nbsp; def &lt;/SPAN&gt;&lt;SPAN&gt;addIntegerSpinnerCommandInput&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;self&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;id&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;str&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;min&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;int&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;max&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;int&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;spinStep&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;int&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;STRONG&gt;initialValue: int&lt;/STRONG&gt;&lt;SPAN&gt;) -&amp;gt; &lt;/SPAN&gt;&lt;SPAN&gt;IntegerSpinnerCommandInput&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;How do I set the initial value for a slider? At present this works fine if and only if an acceptable initial value is 0, which in my case is never true. Very often the initial value will be computed based on some other dependent variables and I will need to update the "initial" value inside the change handler.&amp;nbsp; Is there some sample code with this in it?&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Sat, 16 Apr 2022 15:54:15 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11109818#M6152</guid>
      <dc:creator>tim.collins29V9X</dc:creator>
      <dc:date>2022-04-16T15:54:15Z</dc:date>
    </item>
    <item>
      <title>Re: How do I set the initial value and also an updated value for a Python slider control?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11110596#M6153</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/10830800"&gt;@tim.collins29V9X&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;After creating an instance, the valueOne property can be set.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-0f49349e-5ad6-4386-9d78-91da5387e82e" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-0f49349e-5ad6-4386-9d78-91da5387e82e&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# 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)

            sliderIpt: adsk.core.IntegerSliderCommandInput = inputs.addIntegerSliderCommandInput(
                'sliderId',
                'test',
                15,
                32,
                False
            )
            sliderIpt.valueOne = 22

        except:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))


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()))&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 17 Apr 2022 13:14:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11110596#M6153</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2022-04-17T13:14:53Z</dc:date>
    </item>
    <item>
      <title>Re: How do I set the initial value and also an updated value for a Python slider control?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11116887#M6154</link>
      <description>&lt;P&gt;Thanks. My experience as mainly a C++/Java/C# developer gets me in trouble with Python-style coding! This also applies to change events where it seems you have to test for the type of the event sender to know if .value or .valueOne is of intereset.&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 14:36:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11116887#M6154</guid>
      <dc:creator>tim.collins29V9X</dc:creator>
      <dc:date>2022-04-20T14:36:23Z</dc:date>
    </item>
    <item>
      <title>Re: How do I set the initial value and also an updated value for a Python slider control?</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11117506#M6155</link>
      <description>&lt;P&gt;To be more specific why is there both "CommandCreatedEventArgs" and also "CommandCreatedEvent"?&amp;nbsp; Why does the API talk about passing in the "args" object (which is how Python handles variable length arguments) when the event is always a single argument? Why does one ever "cast()" -- ever?&amp;nbsp; I have about a hundred questions along these lines but I think I need to stop here.&amp;nbsp; &amp;nbsp;Anyone?&lt;/P&gt;</description>
      <pubDate>Wed, 20 Apr 2022 18:42:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/how-do-i-set-the-initial-value-and-also-an-updated-value-for-a/m-p/11117506#M6155</guid>
      <dc:creator>tim.collins29V9X</dc:creator>
      <dc:date>2022-04-20T18:42:59Z</dc:date>
    </item>
  </channel>
</rss>

