<?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: OK Button Control in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9248345#M12889</link>
    <description>&lt;P&gt;That's the way I came up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;・During the command activate event, two SelectionCommandInputs are forcibly selected and a ValidateInput event is generated.&lt;BR /&gt;　↓&lt;BR /&gt;・During the ValidateInput event, assign the generated ValidateInputsEventArgs to a variable with a large scope.&lt;BR /&gt;　↓&lt;BR /&gt;・ Empty two SelectionCommandInput.&lt;BR /&gt;　↓&lt;BR /&gt;・ Check the condition during the InputChange event and enable / disable the OK button.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought this would work, but I couldn't.&lt;/P&gt;
&lt;PRE&gt;# python script
import adsk.core, adsk.fusion, traceback

_commandId = 'ValidateInputs'
_input1ID = 'Selectioninput1'
_input2ID = 'Selectioninput2'

_handlers = []
_app = None
_ui = None
_valiIptEvtArgs = adsk.core.ValidateInputsEventArgs.cast(None)

class CommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class ValidateInputHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        global _valiIptEvtArgs
        if _valiIptEvtArgs is not None:
            return

        try:
            _valiIptEvtArgs = adsk.core.ValidateInputsEventArgs.cast(args)

            _ui.messageBox('call ValidateInputs')
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class InputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        global _valiIptEvtArgs
        if _valiIptEvtArgs is None:
            return

        try:
            inputs = args.inputs
            i1 :adsk.core.SelectionCommandInput = inputs.itemById(_input1ID)
            i2 :adsk.core.SelectionCommandInput = inputs.itemById(_input2ID)

            if i1.selectionCount &amp;gt; 0 and i2.selectionCount &amp;gt; 0:
                _valiIptEvtArgs.areInputsValid = True
            else:
                _valiIptEvtArgs.areInputsValid = False
                
            _ui.messageBox('InputChangedHandler')
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class ActivateHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        if _valiIptEvtArgs is not None:
            return

        try:
            inputs = args.command.commandInputs
            i1 = inputs.itemById(_input1ID)
            i2 = inputs.itemById(_input2ID)

            root = _app.activeProduct.rootComponent
            i1.addSelection(root.xYConstructionPlane)
            i2.addSelection(root.yZConstructionPlane)

            # call ValidateInput

            i1.clearSelection()
            i2.clearSelection()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = args.command

            onDestroy = CommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onValidateInput = ValidateInputHandler()
            cmd.validateInputs.add(onValidateInput)
            _handlers.append(onValidateInput)

            onActivate = ActivateHandler()
            cmd.activate.add(onActivate)
            _handlers.append(onActivate)

            onInputChanged = InputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            _handlers.append(onInputChanged)

            inputs = cmd.commandInputs
            i1 = inputs.addSelectionInput(_input1ID, _input1ID,  _input1ID)
            i1.setSelectionLimits(1,1)
            i2 = inputs.addSelectionInput(_input2ID, _input2ID,  _input2ID)
            i2.setSelectionLimits(1,1)

        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDefs = _ui.commandDefinitions

        cmdDef = cmdDefs.itemById(_commandId)
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)

        onCmdCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCmdCreated)
        _handlers.append(onCmdCreated)
        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to achieve is, for example, the state of a sweep command.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 322px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/716430i65604DBD66B7C319/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you select a profile and no path is selected, the OK button is disabled.&lt;BR /&gt;When the command cannot be executed, it is natural that the OK button is disabled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 14 Jan 2020 00:10:01 GMT</pubDate>
    <dc:creator>kandennti</dc:creator>
    <dc:date>2020-01-14T00:10:01Z</dc:date>
    <item>
      <title>OK Button Control</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9246517#M12888</link>
      <description>&lt;P&gt;Hello everyone. It will be helpful if you can tell me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am testing a script(addButtonDefinition) with two SelectionCommandInput.&lt;/P&gt;
&lt;P&gt;The desired method is to enable the OK button only when two SelectionCommandInputs are selected, and to disable the button otherwise.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand that you can control the OK button with the areInputsValid property of the ValidateInputsEventArgs object.&lt;BR /&gt;However, the firing of ValidateInputsEvent is the timing when two SelectionCommandInputs are selected.&lt;/P&gt;
&lt;P&gt;In the following code, if one is selected, the OK button will be enabled and the ValidateInputsEvent will not occur, so the OK button cannot be controlled. How should I do it?&lt;/P&gt;
&lt;P&gt;Thanks in advance.&lt;/P&gt;
&lt;PRE&gt;# python script
import adsk.core, adsk.fusion, traceback

_commandId = 'ValidateInputs'
_input1ID = 'Selectioninput1'
_input2ID = 'Selectioninput2'

_handlers = []
_app = None
_ui = None

class CommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class ValidateInputHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)

            inputs = args.inputs
            i1 :adsk.core.SelectionCommandInput = inputs.itemById(_input1ID)
            i2 :adsk.core.SelectionCommandInput = inputs.itemById(_input2ID)

            if i1.selectionCount &amp;gt; 0 and i2.selectionCount &amp;gt; 0:
                eventArgs.areInputsValid = True
            else:
                eventArgs.areInputsValid = False
                
            _ui.messageBox('call ValidateInputs')
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = args.command

            onDestroy = CommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onValidateInput = ValidateInputHandler()
            cmd.validateInputs.add(onValidateInput)
            _handlers.append(onValidateInput)

            inputs = cmd.commandInputs
            i1 = inputs.addSelectionInput(_input1ID, _input1ID,  _input1ID)
            i1.setSelectionLimits(1,1)
            i2 = inputs.addSelectionInput(_input2ID, _input2ID,  _input2ID)
            i2.setSelectionLimits(1,1)

        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDefs = _ui.commandDefinitions

        cmdDef = cmdDefs.itemById(_commandId)
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)

        onCmdCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCmdCreated)
        _handlers.append(onCmdCreated)
        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="OKButton.png" style="width: 242px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/716114i9F60012F373879AF/image-size/large?v=v2&amp;amp;px=999" role="button" title="OKButton.png" alt="OKButton.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Jan 2020 09:09:45 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9246517#M12888</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-01-13T09:09:45Z</dc:date>
    </item>
    <item>
      <title>Re: OK Button Control</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9248345#M12889</link>
      <description>&lt;P&gt;That's the way I came up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;・During the command activate event, two SelectionCommandInputs are forcibly selected and a ValidateInput event is generated.&lt;BR /&gt;　↓&lt;BR /&gt;・During the ValidateInput event, assign the generated ValidateInputsEventArgs to a variable with a large scope.&lt;BR /&gt;　↓&lt;BR /&gt;・ Empty two SelectionCommandInput.&lt;BR /&gt;　↓&lt;BR /&gt;・ Check the condition during the InputChange event and enable / disable the OK button.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I thought this would work, but I couldn't.&lt;/P&gt;
&lt;PRE&gt;# python script
import adsk.core, adsk.fusion, traceback

_commandId = 'ValidateInputs'
_input1ID = 'Selectioninput1'
_input2ID = 'Selectioninput2'

_handlers = []
_app = None
_ui = None
_valiIptEvtArgs = adsk.core.ValidateInputsEventArgs.cast(None)

class CommandDestroyHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            adsk.terminate()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class ValidateInputHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        global _valiIptEvtArgs
        if _valiIptEvtArgs is not None:
            return

        try:
            _valiIptEvtArgs = adsk.core.ValidateInputsEventArgs.cast(args)

            _ui.messageBox('call ValidateInputs')
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class InputChangedHandler(adsk.core.InputChangedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        global _valiIptEvtArgs
        if _valiIptEvtArgs is None:
            return

        try:
            inputs = args.inputs
            i1 :adsk.core.SelectionCommandInput = inputs.itemById(_input1ID)
            i2 :adsk.core.SelectionCommandInput = inputs.itemById(_input2ID)

            if i1.selectionCount &amp;gt; 0 and i2.selectionCount &amp;gt; 0:
                _valiIptEvtArgs.areInputsValid = True
            else:
                _valiIptEvtArgs.areInputsValid = False
                
            _ui.messageBox('InputChangedHandler')
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class ActivateHandler(adsk.core.CommandEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        if _valiIptEvtArgs is not None:
            return

        try:
            inputs = args.command.commandInputs
            i1 = inputs.itemById(_input1ID)
            i2 = inputs.itemById(_input2ID)

            root = _app.activeProduct.rootComponent
            i1.addSelection(root.xYConstructionPlane)
            i2.addSelection(root.yZConstructionPlane)

            # call ValidateInput

            i1.clearSelection()
            i2.clearSelection()
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

class CommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            cmd = args.command

            onDestroy = CommandDestroyHandler()
            cmd.destroy.add(onDestroy)
            _handlers.append(onDestroy)

            onValidateInput = ValidateInputHandler()
            cmd.validateInputs.add(onValidateInput)
            _handlers.append(onValidateInput)

            onActivate = ActivateHandler()
            cmd.activate.add(onActivate)
            _handlers.append(onActivate)

            onInputChanged = InputChangedHandler()
            cmd.inputChanged.add(onInputChanged)
            _handlers.append(onInputChanged)

            inputs = cmd.commandInputs
            i1 = inputs.addSelectionInput(_input1ID, _input1ID,  _input1ID)
            i1.setSelectionLimits(1,1)
            i2 = inputs.addSelectionInput(_input2ID, _input2ID,  _input2ID)
            i2.setSelectionLimits(1,1)

        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

def run(context):
    try:
        global _app, _ui
        _app = adsk.core.Application.get()
        _ui = _app.userInterface

        cmdDefs = _ui.commandDefinitions

        cmdDef = cmdDefs.itemById(_commandId)
        if cmdDef:
            cmdDef.deleteMe()

        cmdDef = cmdDefs.addButtonDefinition(_commandId, _commandId, _commandId)

        onCmdCreated = CommandCreatedHandler()
        cmdDef.commandCreated.add(onCmdCreated)
        _handlers.append(onCmdCreated)
        cmdDef.execute()

        adsk.autoTerminate(False)
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I want to achieve is, for example, the state of a sweep command.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 322px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/716430i65604DBD66B7C319/image-size/large?v=v2&amp;amp;px=999" role="button" title="1.png" alt="1.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;If you select a profile and no path is selected, the OK button is disabled.&lt;BR /&gt;When the command cannot be executed, it is natural that the OK button is disabled.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 00:10:01 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9248345#M12889</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-01-14T00:10:01Z</dc:date>
    </item>
    <item>
      <title>Re: OK Button Control</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9249102#M12890</link>
      <description>&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Hi, Kondennti-san,&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I am not sure if I fully understand the issue (had only very short glimpse at the post),&lt;/P&gt;&lt;P&gt;but if you want OK button active for both scenarios:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT color="#0000FF"&gt;1.)&amp;nbsp; Selectioninput1=selected and&amp;nbsp;&amp;nbsp;Selectioninput2=selected&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT color="#0000FF"&gt;2.)&amp;nbsp; Selectioninput1=selected and&amp;nbsp;&amp;nbsp;Selectioninput2=not_selected&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;consider dynamically switch between as required:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;FONT color="#0000FF"&gt;Selectioninput2.setSelectionLimits(1,1) &amp;lt;==&amp;gt; Selectioninput2.setSelectionLimits(0)&lt;/FONT&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;Regards&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;MichaelT&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 14 Jan 2020 10:50:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9249102#M12890</guid>
      <dc:creator>MichaelT_123</dc:creator>
      <dc:date>2020-01-14T10:50:19Z</dc:date>
    </item>
    <item>
      <title>Re: OK Button Control</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9251189#M12891</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2900239"&gt;@MichaelT_123&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By setting to setSelectionLimits (0), we found that ValidateInput event occurs frequently. It seems we can solve it.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did not understand the timing of firing the ValidateInput event at all. . .&lt;BR /&gt;(Even if you click on nothing, it will fire)&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jan 2020 02:52:23 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/ok-button-control/m-p/9251189#M12891</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-01-15T02:52:23Z</dc:date>
    </item>
  </channel>
</rss>

