Message 1 of 4
Unexpected behavior with ui.activeSelections
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I'm trying to write a script that does essentially the following:
- Find bodies inside components.
- Select them.
- Create a selection set from the selected bodies.
- Deselect them
- Select other bodies.
- Create a selection set from these selected bodies.
- Deselect them.
- Repeat
I've managed to write a script that successfully finds bodies inside a design, select them, and then is supposed to create a selection set from them. However, when I run
ui.activeSelections.clear()
to clear the selections, the selection set created by the script is empty.
I don't really get it, and I'm kind of at a loss as to what to do. Here's the script:
#Author-
#Description-
# https://forums.autodesk.com/t5/fusion-360-api-and-scripts/api-for-working-with-selection-sets/td-p/8837150
import adsk.core, adsk.fusion, adsk.cam, traceback
import re
# Produces empty selection set when it should produce a selection set containing selected bodies then clear the selection set.
def run(context):
ui = None
try:
app = adsk.core.Application.get()
ui = app.userInterface
design = app.activeProduct
rootComponent = design.rootComponent
# Add all bodies in components to acrtive selections
allComponents = rootComponent.allOccurrences
for component in allComponents:
componentName = component.name.split(':')[0]
bRepBodies = component.bRepBodies
for body in bRepBodies:
ui.activeSelections.add(body)
# Create selection set
cmd = ui.commandDefinitions.itemById('CreateSelectionGroupCmd')
cmd.execute()
# Clear selections
ui.activeSelections.clear()
except:
if ui:
ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))I made a screencast of the script creating an empty selection set. Here's a direct link in case it doesn't work: https://autode.sk/36elSyz
And I've also attached the test design illustrating the problem.
Thanks for the help, and I'm happy to answer any questions!