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.
Solved! Go to Solution.
Solved by kandennti. Go to Solution.
In Fusion, there is essentially one selection set. In Fusion, when no other command is running the Select command is running. 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).
The API lets you interact with the set of entities currently selected, when the Select command is running. You use the activeSelections property of the UserInterface object. This returns a Selections object which is a collection that contains everything that's currently selected. Using functions on the Selections object, you can add and remove entities and clear the entire set. The UserInterface object is accessed through the userInterface property on the Application object.
Thank you @BrianEkins for your reply. What I am looking for is creating Selection Sets that are listed and managed in the browser.
Suppose I want to create a BRepBody and as by-products create Selection Sets to categorize created BRepFaces (Following picture). Or suppose I want to create bunch of objects and as by-products create a Selection Set for bolts, another for nuts, etc.
Hi nnikbin.
Very limited but I found a way.
First, create multiple bodies in the root component.
Then, execute the next script.
#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()))
After execution, a SelectionSets is created to select the first Body.
It seems that it is possible to call many commands of Fusion360 if doing it this way.
https://help.autodesk.com/view/fusion360/ENU/?guid=GUID-d34065c0-b5b8-46f9-bd4c-36adfcdfda83
The executable command ID list can be written to a file by executing the following code.
#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()))
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.
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).
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.
Sincerely,
A frustrated modeler trying to improve your UI
Amazing solution! Wondering, do you know if there is any guide on what exactly all the commands that are saved in .txt file do?
Hi @Anonymous .
I'm sorry, I didn't understand the meaning.
The method using "executeTextCommand" described here is better than the method described above.
How to use TextCommands is summarized here.
https://forums.autodesk.com/t5/fusion-360-api-and-scripts/use-textcommands/td-p/9645688
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 ui.activeSelections. I made this little example script excerpt below to show how you could do it.
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
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!