Get list of selected objects

Get list of selected objects

grakoczy
Contributor Contributor
3,052 Views
2 Replies
Message 1 of 3

Get list of selected objects

grakoczy
Contributor
Contributor

Hi,

 

Is there any way to get list of selected bRepBodies or to check if body is selected?

I've found Selection, but how to use it in the python code?

 

-- 

Grzegorz Rakoczy

0 Likes
Accepted solutions (2)
3,053 Views
2 Replies
Replies (2)
Message 2 of 3

ekinsb
Alumni
Alumni
Accepted solution

The current set of selected entities can be obtained through the UserInterface.activeSelections property.  This is demonstrated in the code below that looks through the currence selections to see if any bodies are selected and then displays information about any selected bodies and any other entity types that were selected.

 

import adsk.core, adsk.fusion, traceback

def run(context):
    ui = None
    try:
        app = adsk.core.Application.get()
        ui  = app.userInterface
        
        result = ''
        for selection in ui.activeSelections:
            selectedEnt = selection.entity
            if selectedEnt.objectType == adsk.fusion.BRepBody.classType():
                result += 'Selected Body: ' + selectedEnt.name + '\n'
            else:
                result += 'Other selection: ' + selectedEnt.objectType + '\n'

        ui.messageBox(result, 'Selection Result')
    except:
        if ui:
            ui.messageBox('Failed:\n{}'.format(traceback.format_exc()))

Brian Ekins
Inventor and Fusion 360 API Expert
Mod the Machine blog
Message 3 of 3

grakoczy
Contributor
Contributor
Accepted solution
Thanks, this is what I needed.
0 Likes