<?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: Empty Selection input crashes Add-in in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150957#M523</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11198104"&gt;@danielWNW3M&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code stop firing the execute event when any selection command input have a minimum selection limit, as &lt;STRONG&gt;&lt;EM&gt;planeInput&lt;/EM&gt; &lt;/STRONG&gt;and &lt;STRONG&gt;&lt;EM&gt;wellInput&lt;/EM&gt; &lt;/STRONG&gt;command inputs, and at the moment of the execute event they don't have any selected item.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By default a &lt;EM&gt;SelectionCommandInput&lt;/EM&gt; is defined with limits[1,1] (min and max values).&lt;/P&gt;&lt;P&gt;You can check it after you create the command input with:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    app.log(f'{planeInput.getSelectionLimits()=}')&lt;/LI-CODE&gt;&lt;P&gt;and you'll get:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;planeInput.getSelectionLimits()=[True, 1, 1]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, to make your script run just add:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;...
    planeInput.setSelectionLimits(0)
...
    wellInput.setSelectionLimits(0)
...&lt;/LI-CODE&gt;&lt;P&gt;after you create any of these selection inputs.&amp;nbsp; Or adjust their selection limits as long as you enable/disable them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;One suggestion:&lt;/U&gt; don't use "type" as a variable name since there is a built-in Python function and you're shading it in the scope where it is defined, as in the&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;EM&gt;command_input_changed&lt;/EM&gt; event function.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Jorge Jaramillo&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
    <pubDate>Thu, 14 Nov 2024 18:17:59 GMT</pubDate>
    <dc:creator>Jorge_Jaramillo</dc:creator>
    <dc:date>2024-11-14T18:17:59Z</dc:date>
    <item>
      <title>Empty Selection input crashes Add-in</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13148463#M520</link>
      <description>&lt;P&gt;I'm trying to make an add-in that lets me enter data for one of several geometries. I'm starting with all the necessary inputs created but invisible, then when the user selects which type of geometry they want, I make those inputs visible (and re-hide the others just in case). This works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem is that if I need to include a selectionInput for some of them, and it seems that any time any of them is left empty it kills my add-in. It dies before even getting to the command_execute function, so I can't put up a messageBox with any of the data to help debugging. I've confirmed it's the selection commands just by adding and removing commands until I get the errors again.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm not sure why everything is dying, so I'm not really sure how to fix it. First I tried enabling and disabling the inputs along with making them visible, but as they call out in the documentation that doesn't really work for selectionInputs. I also tried using the &lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-32B73C2F-F430-4244-B335-6DE089000F0D" target="_blank" rel="noopener"&gt;.deleteMe method&lt;/A&gt; to get rid of the ones I don't need, but that just crashes Fusion entirely.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for any help or insight here, I am at a loss at this point.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code that creates the input&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def command_created(args: adsk.core.CommandCreatedEventArgs):
    # General logging for debug.
    futil.log(f'{CMD_NAME} Command Created Event')

    # https://help.autodesk.com/view/fusion360/ENU/?contextId=CommandInputs
    inputs = args.command.commandInputs

    # Create text inputs for the component
    selectionInput0 = inputs.addSelectionInput('component', 'Component', 'Select the component that contains this feature')
    selectionInput0.addSelectionFilter('Occurrences')
    selectionInput0.setSelectionLimits(1)

    # Create a text input for the feature description
    descriptionInput = inputs.addTextBoxCommandInput('description', 'Description', 'xy-plane 1', 1, False)

    # Create dropdown input for feature type selection
    typeInput = inputs.addDropDownCommandInput('type', 'Feature Type', adsk.core.DropDownStyles.TextListDropDownStyle)
    typeList = ['plane', 'well']
    types = typeInput.listItems
    for t in typeList:
        types.add(t, False)

    # Create a selection for a plane surface
    planeInput = inputs.addSelectionInput('plane', 'Plane', 'Select the plane that the feature will be created on')
    planeInput.addSelectionFilter('Faces')
    planeInput.addSelectionFilter('ConstructionPlanes')
    planeInput.addSelectionFilter('Sketches')
    planeInput.isVisible = False

    # Create a selection for points
    pointsInput = inputs.addSelectionInput('points', 'Points', 'Select the points that define the feature')
    pointsInput.addSelectionFilter('SketchPoints')
    pointsInput.addSelectionFilter('ConstructionPoints')
    pointsInput.setSelectionLimits(0)
    pointsInput.isVisible = False

    # Create a selection for well base
    wellInput = inputs.addSelectionInput('wellBase', 'Well Base', 'Select the base of the well')
    wellInput.addSelectionFilter('Faces')
    wellInput.addSelectionFilter('ConstructionPlanes')
    wellInput.addSelectionFilter('Sketches')
    wellInput.isVisible = False

    # Create a value input for well diameter
    diameterInput = inputs.addValueInput('wellDiameter', 'Well Diameter', 'mm', adsk.core.ValueInput.createByReal(0))
    diameterInput.isVisible = False

    # Create a value input for well depth
    depthInput = inputs.addValueInput('wellDepth', 'Well Depth', 'mm', adsk.core.ValueInput.createByReal(0))
    depthInput.isVisible = False
    

    # TODO Connect to the events that are needed by this command.
    futil.add_handler(args.command.execute, command_execute, local_handlers=local_handlers)
    futil.add_handler(args.command.inputChanged, command_input_changed, local_handlers=local_handlers)
    futil.add_handler(args.command.executePreview, command_preview, local_handlers=local_handlers)
    futil.add_handler(args.command.validateInputs, command_validate_input, local_handlers=local_handlers)
    futil.add_handler(args.command.destroy, command_destroy, local_handlers=local_handlers)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code that hides the unused commands:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def command_input_changed(args: adsk.core.InputChangedEventArgs):
    inputs = args.inputs
    cmdInput = args.input
    type: adsk.core.DropDownCommandInput = inputs.itemById('type')

    if cmdInput.id == 'type':
        if type.selectedItem.name == 'plane':
            inputs.itemById('plane').isVisible = True
            inputs.itemById('points').isVisible = True
            inputs.itemById('wellBase').isVisible = False
            inputs.itemById('wellDiameter').isVisible = False
            inputs.itemById('wellDepth').isVisible = False
        elif type.selectedItem.name == 'well':
            inputs.itemById('plane').isVisible = False
            inputs.itemById('points').isVisible = False
            inputs.itemById('wellBase').isVisible = True
            inputs.itemById('wellDiameter').isVisible = True
            inputs.itemById('wellDepth').isVisible = True&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For now my command execute is very simple while I'm trying to debug this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def command_execute(args: adsk.core.CommandEventArgs):
    ui.messageBox("Feature Generator Started")
    # General logging for debug.
    futil.log(f'{CMD_NAME} Command Execute Event')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Nov 2024 16:44:39 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13148463#M520</guid>
      <dc:creator>danielWNW3M</dc:creator>
      <dc:date>2024-11-13T16:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: Empty Selection input crashes Add-in</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13149226#M521</link>
      <description>&lt;P&gt;I have your add-in running, but I don't see a crash. What are the exact steps to cause it to crash?&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 00:41:18 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13149226#M521</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2024-11-14T00:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: Empty Selection input crashes Add-in</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150548#M522</link>
      <description>&lt;P&gt;Thank you so much for the reply!&lt;/P&gt;&lt;P&gt;For me, at least:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;start add-inn&lt;/LI&gt;&lt;LI&gt;select a component&lt;/LI&gt;&lt;LI&gt;select a feature type&lt;/LI&gt;&lt;LI&gt;fill in appropriate data (or not, result is the same)&lt;/LI&gt;&lt;LI&gt;click okay&lt;/LI&gt;&lt;LI&gt;nothing happens, the add-in crashes, the ui.messageBox does not appear.&amp;nbsp;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Here's a quick screen grab&lt;/P&gt;&lt;P&gt;&lt;div class="lia-vid-container video-embed-center"&gt;&lt;div id="lia-vid-6364704174112w898h540r146" class="lia-video-brightcove-player-container"&gt;&lt;video-js data-video-id="6364704174112" data-account="6057940548001" data-player="default" data-embed="default" class="vjs-fluid" controls="" data-application-id="" style="width: 100%; height: 100%;"&gt;&lt;/video-js&gt;&lt;/div&gt;&lt;script src="https://players.brightcove.net/6057940548001/default_default/index.min.js"&gt;&lt;/script&gt;&lt;script&gt;(function() {  var wrapper = document.getElementById('lia-vid-6364704174112w898h540r146');  var videoEl = wrapper ? wrapper.querySelector('video-js') : null;  if (videoEl) {     if (window.videojs) {       window.videojs(videoEl).ready(function() {         this.on('loadedmetadata', function() {           this.el().querySelectorAll('.vjs-load-progress div[data-start]').forEach(function(bar) {             bar.setAttribute('role', 'presentation');             bar.setAttribute('aria-hidden', 'true');           });         });       });     }  }})();&lt;/script&gt;&lt;a class="video-embed-link" href="https://forums.autodesk.com/t5/video/gallerypage/video-id/6364704174112"&gt;(view in My Videos)&lt;/a&gt;&lt;/div&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 15:12:48 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150548#M522</guid>
      <dc:creator>danielWNW3M</dc:creator>
      <dc:date>2024-11-14T15:12:48Z</dc:date>
    </item>
    <item>
      <title>Re: Empty Selection input crashes Add-in</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150957#M523</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/11198104"&gt;@danielWNW3M&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your code stop firing the execute event when any selection command input have a minimum selection limit, as &lt;STRONG&gt;&lt;EM&gt;planeInput&lt;/EM&gt; &lt;/STRONG&gt;and &lt;STRONG&gt;&lt;EM&gt;wellInput&lt;/EM&gt; &lt;/STRONG&gt;command inputs, and at the moment of the execute event they don't have any selected item.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;By default a &lt;EM&gt;SelectionCommandInput&lt;/EM&gt; is defined with limits[1,1] (min and max values).&lt;/P&gt;&lt;P&gt;You can check it after you create the command input with:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    app.log(f'{planeInput.getSelectionLimits()=}')&lt;/LI-CODE&gt;&lt;P&gt;and you'll get:&lt;/P&gt;&lt;LI-CODE lang="general"&gt;planeInput.getSelectionLimits()=[True, 1, 1]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So, to make your script run just add:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;...
    planeInput.setSelectionLimits(0)
...
    wellInput.setSelectionLimits(0)
...&lt;/LI-CODE&gt;&lt;P&gt;after you create any of these selection inputs.&amp;nbsp; Or adjust their selection limits as long as you enable/disable them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;One suggestion:&lt;/U&gt; don't use "type" as a variable name since there is a built-in Python function and you're shading it in the scope where it is defined, as in the&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&lt;EM&gt;command_input_changed&lt;/EM&gt; event function.&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Regards,&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Jorge Jaramillo&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 14 Nov 2024 18:17:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150957#M523</guid>
      <dc:creator>Jorge_Jaramillo</dc:creator>
      <dc:date>2024-11-14T18:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: Empty Selection input crashes Add-in</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150973#M524</link>
      <description>&lt;P&gt;That did it, thank you so much for the solution!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And I have changed "type" as well... thanks for the heads up on that.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Nov 2024 18:28:08 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/empty-selection-input-crashes-add-in/m-p/13150973#M524</guid>
      <dc:creator>danielWNW3M</dc:creator>
      <dc:date>2024-11-14T18:28:08Z</dc:date>
    </item>
  </channel>
</rss>

