<?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: ValidateInputs does not validate... in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7861333#M16469</link>
    <description>&lt;P&gt;I found a solution myself, which is working well, but I have other questions....&lt;BR /&gt;&lt;BR /&gt;Here is the working ValidateInputHandler&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;class SampleCommandValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)
        inputs = eventArgs.firingEvent.sender.commandInputs                
        selLineInput = adsk.core.SelectionCommandInput.cast(inputs.itemById('constructionLineUniqueID'))
        myLine = adsk.fusion.SketchLine.cast(selLineInput.selection(0).entity)
        if myLine.isConstruction:
            eventArgs.areInputsValid = True 
            return
        else:
            eventArgs.areInputsValid = False
            return&lt;/PRE&gt;</description>
    <pubDate>Sat, 17 Mar 2018 02:06:03 GMT</pubDate>
    <dc:creator>Le_Bear</dc:creator>
    <dc:date>2018-03-17T02:06:03Z</dc:date>
    <item>
      <title>ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7860298#M16468</link>
      <description>&lt;P&gt;Slowly progressing toward my first addin creation.&lt;BR /&gt;&lt;BR /&gt;for now I have a single commandInputs, to select a sketchLine, and this is working as expected. But I want this selected line to be a construction line, so I am attempting to check if this is he case inside a ValidateInputs event, but does not seem to work, meaning a regular line is OK too...&lt;BR /&gt;&lt;BR /&gt;Here is the code involved:&lt;/P&gt;&lt;PRE&gt;# Event handler for the commandCreated event.
class onCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        # Verify that a sketch is active.
        app = adsk.core.Application.get()
        if app.activeEditObject.objectType != adsk.fusion.Sketch.classType():
            ui = app.userInterface
            ui.messageBox('A sketch must be active for this command.')
            return False        
        
        eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
        
        #Get the command
        cmd = eventArgs.command
        # Get the CommandInputs collection associated with the command.
        inputs = cmd.commandInputs
        
        constructionLine = inputs.addSelectionInput('constructionLineUniqueID','Select a Construction Line', 'The line you select will be the Chord of your Airfoil' )
        constructionLine.addSelectionFilter('SketchLines')

        # Connect to the execute event.
        onExecute = SampleCommandExecuteHandler()
        cmd.execute.add(onExecute)
        handlers.append(onExecute)         

#        #Connect to the ValidateInputs Event
        onValidate = SampleCommandValidateInputsHandler()
        cmd.validateInputs.add(onValidate)
        handlers.append(onValidate)
        
class SampleCommandValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)
        inputs = eventArgs.firingEvent.sender.commandInputs        
        
        selLine = inputs.itemById('constructionLineUniqueID') 
                        
        if selLine.objectType == adsk.fusion.SketchLine.classType():
            myLine = adsk.fusion.SketchLine.cast(selLine)
            
        if myLine.isConstruction:
            eventArgs.areInputsValid = True 
            return
        else:
            eventArgs.areInputsValid = False
            return&lt;/PRE&gt;&lt;P&gt;&lt;BR /&gt;Checking with the debugger, I can see the objectType for selLine is NOT sketchLine....Guess I have to find the way to make it so?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 16:48:11 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7860298#M16468</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-16T16:48:11Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7861333#M16469</link>
      <description>&lt;P&gt;I found a solution myself, which is working well, but I have other questions....&lt;BR /&gt;&lt;BR /&gt;Here is the working ValidateInputHandler&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;class SampleCommandValidateInputsHandler(adsk.core.ValidateInputsEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        eventArgs = adsk.core.ValidateInputsEventArgs.cast(args)
        inputs = eventArgs.firingEvent.sender.commandInputs                
        selLineInput = adsk.core.SelectionCommandInput.cast(inputs.itemById('constructionLineUniqueID'))
        myLine = adsk.fusion.SketchLine.cast(selLineInput.selection(0).entity)
        if myLine.isConstruction:
            eventArgs.areInputsValid = True 
            return
        else:
            eventArgs.areInputsValid = False
            return&lt;/PRE&gt;</description>
      <pubDate>Sat, 17 Mar 2018 02:06:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7861333#M16469</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-17T02:06:03Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7861336#M16470</link>
      <description>&lt;P&gt;Now, the question is:&lt;BR /&gt;&lt;BR /&gt;How can I let the user know that the OK button is disabled because he did not select a construction line? I believe it would be nice to let the user know why his selection does not pass the validation test.&lt;BR /&gt;&lt;BR /&gt;Thanks for any help!&lt;BR /&gt;Bernard&lt;/P&gt;</description>
      <pubDate>Sat, 17 Mar 2018 02:09:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7861336#M16470</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-17T02:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7863608#M16471</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;One sample you would be able to refer to is "Spur Gear". It shows prompt message at the bottom of dialog when users give invalid inputs.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;Marshal&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Prompts.png" style="width: 292px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/477263i9907805A1F4091E1/image-size/large?v=v2&amp;amp;px=999" role="button" title="Prompts.png" alt="Prompts.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 02:07:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7863608#M16471</guid>
      <dc:creator>marshaltu</dc:creator>
      <dc:date>2018-03-19T02:07:39Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7863727#M16472</link>
      <description>&lt;P&gt;What you want to use in this case is the selectionEvent of the Command object.&amp;nbsp; For the selection input you can only filter using types of objects, but using the selectionEvent&amp;nbsp;you can use any criteria you want for what the user can select.&amp;nbsp; As the user is moving the mouse over the model to select something the selectionEvent is fired before it is highlighted to the user and you can look at what the mouse is currently over and choose whether it should be made selectable or not.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 03:58:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7863727#M16472</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2018-03-19T03:58:40Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7864144#M16473</link>
      <description>&lt;P&gt;That's an idea, I will like how this is done. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 08:42:44 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7864144#M16473</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-19T08:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7864148#M16474</link>
      <description>&lt;P&gt;I did try the selectionEvent, but it was not working for me, maybe I had bug. It would be the best if it worked. I will experiment with it again. Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 08:44:47 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7864148#M16474</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-19T08:44:47Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7864770#M16475</link>
      <description>&lt;P&gt;I did use a textBox with an HTML formated text, works well. Thanks, did not thought I could use it this way.&lt;/P&gt;</description>
      <pubDate>Mon, 19 Mar 2018 12:58:42 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7864770#M16475</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-19T12:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7866178#M16476</link>
      <description>&lt;P&gt;Here's a variation of your code that uses the selection input event to limit the selection to construction lines.&amp;nbsp; I think it's best to try and control the selection to get it correct the first time rather than let them select anything and then report the problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;# Event handler for the commandCreated event.
class onCommandCreatedEventHandler(adsk.core.CommandCreatedEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        # Verify that a sketch is active.
        if _app.activeEditObject.objectType != adsk.fusion.Sketch.classType():
            _ui.messageBox('A sketch must be active for this command.')
            return False        
        
        eventArgs = adsk.core.CommandCreatedEventArgs.cast(args)
        
        #Get the command
        cmd = eventArgs.command

        # Get the CommandInputs collection associated with the command.
        inputs = cmd.commandInputs
        
        constructionLine = inputs.addSelectionInput('constructionLineUniqueID','Select a Construction Line', 'The line you select will be the Chord of your Airfoil' )
        constructionLine.addSelectionFilter('SketchLines')

        # Connect to the execute event.
        onExecute = SampleCommandExecuteHandler()
        cmd.execute.add(onExecute)
        _handlers.append(onExecute)         

        # Connect to the Selection event.
        onSelectionEvent = SampleCommandSelectionEventHandler()
        cmd.selectionEvent.add(onSelectionEvent)
        _handlers.append(onSelectionEvent)


# Event handler for the selectionEvent event.
class SampleCommandSelectionEventHandler(adsk.core.SelectionEventHandler):
    def __init__(self):
        super().__init__()
    def notify(self, args):
        try:
            eventArgs = adsk.core.SelectionEventArgs.cast(args)
    
            skLine = adsk.fusion.SketchLine.cast(eventArgs.selection.entity)
            if skLine.isConstruction:
                eventArgs.isSelectable = True
            else:
                eventArgs.isSelectable = False
        except:
            if _ui:
                _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;</description>
      <pubDate>Mon, 19 Mar 2018 19:58:06 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7866178#M16476</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2018-03-19T19:58:06Z</dc:date>
    </item>
    <item>
      <title>Re: ValidateInputs does not validate...</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7867441#M16477</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5741855"&gt;@BrianEkins&lt;/a&gt;wrote:&lt;BR /&gt;&lt;P&gt;Here's a variation of your code that uses the selection input event to limit the selection to construction lines.&amp;nbsp; I think it's best to try and control the selection to get it correct the first time rather than let them select anything and then report the problems.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;&lt;P&gt;Thanks Brian, not sure what I did wrong when I tried the first time, but tis works perfectly!&lt;/P&gt;&lt;/BLOCKQUOTE&gt;</description>
      <pubDate>Tue, 20 Mar 2018 09:18:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/validateinputs-does-not-validate/m-p/7867441#M16477</guid>
      <dc:creator>Le_Bear</dc:creator>
      <dc:date>2018-03-20T09:18:54Z</dc:date>
    </item>
  </channel>
</rss>

