<?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: API for working with Selection Sets in Fusion API and Scripts Forum</title>
    <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/11476453#M14078</link>
    <description>&lt;P&gt;I agree with others that the syntax for working with selections is a little counter-intuitive and that the documentation for interacting with them is sorely lacking. At least just one little example script would be very helpful. For practical purposes, most of the time you're just going to need to get the set of what's currently selected which would be &lt;STRONG&gt;ui.activeSelections&lt;/STRONG&gt;. I made this little example script excerpt below to show how you could do it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core

app = adsk.core.Application.get()
ui = app.userInterface
selections = ui.activeSelections

# Now you can interact with our selections object like this:
active_sketch = adsk.core.Application.get().activeEditObject
curves = active_sketch.sketchCurves
for curve in curves: # Walk through all the curves in the current sketch 
    selections.add(curve) # Add each of the curves to the selections&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;This example would get the set of currently selected entities, then add all of the curves of the current sketch to it, effectively selecting all curves in the active sketch. Hope this is helpful!&lt;/P&gt;</description>
    <pubDate>Wed, 12 Oct 2022 01:51:49 GMT</pubDate>
    <dc:creator>therealsamchaney</dc:creator>
    <dc:date>2022-10-12T01:51:49Z</dc:date>
    <item>
      <title>API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8837150#M14070</link>
      <description>&lt;P&gt;I checked the documentation to find a way to create Selection Sets. It looks there isn't any API for working with them (checking, creating, deleting, etc). I think it will be useful to have such API. I was wondering whether Autodesk has any plan to expose Selection Sets to Fusion 360 API.&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 18:53:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8837150#M14070</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2019-06-06T18:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8837701#M14071</link>
      <description>&lt;P&gt;In Fusion, there is essentially one selection set.&amp;nbsp; In Fusion, when no other command is running the Select command is running.&amp;nbsp; A command is always running, either the Selection command or some other command. When the Select command is running and you select entities they're being added to the current selection (select set).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The API lets you interact with the set of entities currently selected, when the Select command is running.&lt;SPAN&gt;&amp;nbsp;You use the activeSelections property of the UserInterface object.&amp;nbsp; This returns a Selections object which is a collection that contains everything that's currently selected.&amp;nbsp; Using functions on the Selections object, you can add and remove entities and clear the entire set.&amp;nbsp; The UserInterface object is accessed through the userInterface property on the Application object.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Jun 2019 23:59:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8837701#M14071</guid>
      <dc:creator>BrianEkins</dc:creator>
      <dc:date>2019-06-06T23:59:26Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8838024#M14072</link>
      <description>&lt;P&gt;Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/5741855"&gt;@BrianEkins&lt;/a&gt;&amp;nbsp;for your reply. What I am looking for is creating Selection Sets that&amp;nbsp;are listed and managed in the browser.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I want to create a BRepBody and as by-products create Selection Sets to categorize created BRepFaces (Following picture).&amp;nbsp;Or suppose I want to create bunch of objects and as by-products create a Selection Set for bolts, another for nuts, etc.&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="16.png" style="width: 620px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/645018iB6B9BFD30FFFEE3B/image-size/large?v=v2&amp;amp;px=999" role="button" title="16.png" alt="16.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 06:43:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8838024#M14072</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2019-06-07T06:43:49Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8839242#M14073</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class=""&gt;&lt;A id="link_12" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/2799701" target="_self"&gt;nnikbin&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Very limited but I found a way.&lt;/P&gt;
&lt;P&gt;First, create multiple bodies in the root component.&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="1.png" style="width: 546px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/645236i864991D4A5E6EDB5/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;Then, execute the next script.&lt;/P&gt;
&lt;PRE&gt;#fusion360 python
#Test Create SelectionSets
import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        des = adsk.fusion.Design.cast(app.activeProduct)
        root = des.rootComponent
        
        #Select the first body
        ui.activeSelections.add(root.bRepBodies.item(0))
        
        #Create SelectionSets
        cmd = ui.commandDefinitions.itemById('CreateSelectionGroupCmd')
        cmd.execute()
        
        #Update SelectionSets
        cmd = ui.commandDefinitions.itemById('UpdateSelectionGroupCmd')
        cmd.execute()
        
    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;After execution, a SelectionSets is created to select the first Body.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2.png" style="width: 560px;"&gt;&lt;img src="https://forums.autodesk.com/t5/image/serverpage/image-id/645237i7E64F067E2530C60/image-size/large?v=v2&amp;amp;px=999" role="button" title="2.png" alt="2.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;It seems that it is possible to call many commands of Fusion360 if doing it this way.&lt;BR /&gt;&lt;A href="https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d34065c0-b5b8-46f9-bd4c-36adfcdfda83" target="_blank" rel="noopener"&gt;https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d34065c0-b5b8-46f9-bd4c-36adfcdfda83&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The executable command ID list can be written to a file by executing the following code.&lt;/P&gt;
&lt;PRE&gt;#fusion360 python
#CommandID Write to File
import adsk.core, adsk.fusion, traceback

def run(context):
    try:
        app = adsk.core.Application.get()
        ui = app.userInterface
        
        cmds = [cmd.id for cmd in ui.commandDefinitions]
        path = r'C:\temp\fusion360_commands_list.txt'
        output = open(path, 'w')
        output.writelines('\n'.join(cmds))
        output.close()        
        
    except:
        if _ui:
            _ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 16:21:03 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8839242#M14073</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2019-06-07T16:21:03Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8839410#M14074</link>
      <description>&lt;P&gt;Wonderful! Thank you&amp;nbsp;&lt;a href="https://forums.autodesk.com/t5/user/viewprofilepage/user-id/3787950"&gt;@kandennti&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jun 2019 17:52:54 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8839410#M14074</guid>
      <dc:creator>nnikbin</dc:creator>
      <dc:date>2019-06-07T17:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8856923#M14075</link>
      <description>&lt;P&gt;To the Autodesk employees looking at this issue (if any): this is not resolved! The way of doing this is really ugly, and you can't cleanly access existing selection sets or anything like that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Overall the API support for automating the user interface is almost nonexistent. Just look at the selection filters in the main window for example: there is no API for changing those outside of a command context but yet I can see a load of things I would use that API for. Obviously there is internal API, otherwise it wouldn't be usable at all. Please release these things (or if you really don't want to do this, release debug symbols).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please add actual API for selection sets OR implement temporary view groups like Revit has. I'll take either because they will have the same result, but the former is probably easier for you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sincerely,&lt;/P&gt;&lt;P&gt;A frustrated modeler trying to improve your UI&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jun 2019 06:17:05 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/8856923#M14075</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2019-06-18T06:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/9646266#M14076</link>
      <description>&lt;P&gt;Amazing solution! Wondering, do you know if there is any guide on what exactly all the commands that are saved in .txt &amp;nbsp; file do?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Jul 2020 09:37:35 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/9646266#M14076</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2020-07-21T09:37:35Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/9648118#M14077</link>
      <description>&lt;P&gt;Hi @Anonymous&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm sorry, I didn't understand the meaning.&lt;/P&gt;
&lt;P&gt;The method using "executeTextCommand" described here is better than the method described above.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/unexpected-behavior-with-ui-activeselections/m-p/9520878#M10185" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/unexpected-behavior-with-ui-activeselections/m-p/9520878#M10185&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to use TextCommands is summarized here.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/td-p/9645688" target="_blank" rel="noopener"&gt;https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/td-p/9645688&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jul 2020 01:09:38 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/9648118#M14077</guid>
      <dc:creator>kandennti</dc:creator>
      <dc:date>2020-07-22T01:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: API for working with Selection Sets</title>
      <link>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/11476453#M14078</link>
      <description>&lt;P&gt;I agree with others that the syntax for working with selections is a little counter-intuitive and that the documentation for interacting with them is sorely lacking. At least just one little example script would be very helpful. For practical purposes, most of the time you're just going to need to get the set of what's currently selected which would be &lt;STRONG&gt;ui.activeSelections&lt;/STRONG&gt;. I made this little example script excerpt below to show how you could do it.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import adsk.core

app = adsk.core.Application.get()
ui = app.userInterface
selections = ui.activeSelections

# Now you can interact with our selections object like this:
active_sketch = adsk.core.Application.get().activeEditObject
curves = active_sketch.sketchCurves
for curve in curves: # Walk through all the curves in the current sketch 
    selections.add(curve) # Add each of the curves to the selections&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;BR /&gt;This example would get the set of currently selected entities, then add all of the curves of the current sketch to it, effectively selecting all curves in the active sketch. Hope this is helpful!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Oct 2022 01:51:49 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/fusion-api-and-scripts-forum/api-for-working-with-selection-sets/m-p/11476453#M14078</guid>
      <dc:creator>therealsamchaney</dc:creator>
      <dc:date>2022-10-12T01:51:49Z</dc:date>
    </item>
  </channel>
</rss>

