Message 1 of 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am confused on how to use the selection Event, it is only returning the first item that is selected when I select multiple items. When I select component1:1 it correctly logs that, but when I select the next component, it logs the first item again.
import adsk.core,adsk.fusion,adsk.cam
from .lib import fusion360utils as futil
app = adsk.core.Application.get()
ui = app.userInterface
selections = []
def command_created(args: adsk.core.CommandCreatedEventArgs):
'''Function that is called when a user clicks the corresponding button in the UI. This defines the contents of the command dialog and connects to the command related events.'''
cmd = args.command
inputs = cmd.commandInputs
# Add All Handlers
futil.add_handler(cmd.execute, command_execute)
futil.add_handler(cmd.destroy, command_destroy)
futil.add_handler(cmd.select, command_select)
futil.add_handler(cmd.unselect, command_unSelect)
cmdSelections = inputs.addSelectionInput("itemSelector","Selections","")
cmdSelections.addSelectionFilter(adsk.core.SelectionCommandInput.Occurrences)
cmdSelections.setSelectionLimits(1,0)
def command_select(args:adsk.core.SelectionEventArgs):
selection:adsk.fusion.Occurrence = args.selection.entity
app.log(f"selecting: {selection.name}")
if selection:
if selection.name not in selections:
selections.append(selection.name)
def command_unSelect(args:adsk.core.SelectionEventArgs):
selection:adsk.fusion.Occurrence = args.selection.entity
app.log(f"unselecting: {selection.name}")
if selection:
if selection.name in selections:
selections.remove(selection.name)
def command_execute(args:adsk.core.CommandEventArgs):
app.log(f'{selections}')
def command_destroy(args: adsk.core.CommandEventArgs):
app.log("DESTORY")
pass
Solved! Go to Solution.