<?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: UserParameters.add causing SelectionCommandInput.selection to be empty in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10661336#M7860</link>
    <description>&lt;P&gt;Selections are somewhat fragile and it's by design that when you perform an operation that makes a change to persistent data that the current selections are cleared.&amp;nbsp; To work around this you can get the entities currently selected and save them in a variable and then do your work using these saved references.&lt;/P&gt;</description>
    <pubDate>Fri, 01 Oct 2021 19:12:53 GMT</pubDate>
    <dc:creator>BrianEkins</dc:creator>
    <dc:date>2021-10-01T19:12:53Z</dc:date>
    <item>
      <title>UserParameters.add causing SelectionCommandInput.selection to be empty</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10656623#M7858</link>
      <description>&lt;P&gt;I created a command script that will generate multiple offsets from a single-loop Profile.&lt;/P&gt;&lt;P&gt;The command inputs are:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;A SelectionInput filtered for 1 Profile&lt;/LI&gt;&lt;LI&gt;An IntegerSpinnerCommandInput to specify the number of sketch curves to generate.&lt;/LI&gt;&lt;LI&gt;A DistanceValueCommandInput to specify the total offset distance to span.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;I decided to add a userParameter for the totalOffsetDistance so that I could make adjustments. Adding this line of code..&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;design.userParameters.add('totalOffsetDistance',&amp;nbsp;ValueInput.createByReal(totalOffsetDistance),&amp;nbsp;"cm",&amp;nbsp;"")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;SPAN style="font-family: inherit;"&gt;to the execute handler&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN style="font-family: inherit;"&gt;gives two different behaviors based on whether it is before or after this (assuming there is exactly 1 valid Profile selected).&lt;/SPAN&gt;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;profileSelectionCommand:SelectionCommandInput = inputs.itemById('profileSelection')
profileSelection:Selection = profileSelectionCommand.selection(0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the UserParameter is added before the selection is gotten, it we get an invalid index and we can test to see that the selectionCount is indeed 0. However, if we move that line afterwards, we are able to retrieve the selected Profile just as normal. It's not hard to work around but it is undocumented/unregulated and perhaps unintended behavior from a software engineering perspective.&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 01:25:19 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10656623#M7858</guid>
      <dc:creator>mcd8604</dc:creator>
      <dc:date>2021-09-30T01:25:19Z</dc:date>
    </item>
    <item>
      <title>Re: UserParameters.add causing SelectionCommandInput.selection to be empty</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10659021#M7859</link>
      <description>&lt;P&gt;Interesting, nice discovery&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 Sep 2021 20:13:57 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10659021#M7859</guid>
      <dc:creator>Bowen.Christopher58NJL</dc:creator>
      <dc:date>2021-09-30T20:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: UserParameters.add causing SelectionCommandInput.selection to be empty</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10661336#M7860</link>
      <description>&lt;P&gt;Selections are somewhat fragile and it's by design that when you perform an operation that makes a change to persistent data that the current selections are cleared.&amp;nbsp; To work around this you can get the entities currently selected and save them in a variable and then do your work using these saved references.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 19:12:53 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10661336#M7860</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2021-10-01T19:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: UserParameters.add causing SelectionCommandInput.selection to be empty</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10661473#M7861</link>
      <description>&lt;P&gt;I see. Thanks for the clarification! I ended up creating a utility method to make this easier:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="general"&gt;def GetSelections(sci:SelectionCommandInput):
    return [sci.selection(i) for i in range(sci.selectionCount)]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just have to make sure to remember to cache references prior to making any changes to persistent data.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Oct 2021 20:43:59 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/userparameters-add-causing-selectioncommandinput-selection-to-be/m-p/10661473#M7861</guid>
      <dc:creator>mcd8604</dc:creator>
      <dc:date>2021-10-01T20:43:59Z</dc:date>
    </item>
  </channel>
</rss>

