Message 1 of 2
How to handle hanlders with multiple selection inputs

Not applicable
06-21-2021
07:41 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I am trying to write a script with 2 selection inputs, but I am unable to figure out how to add the selections to my 2 different list with my handler. Is there a way to know which selection triggered the call to the handler?
import adsk.core, adsk.fusion, adsk.cam, traceback
ui = adsk.core.UserInterface.cast(None)
handlers = []
sourceBodies = []
targetBodies = []
class MyCommandCreatedHandler(adsk.core.CommandCreatedEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
cmd = args.command
cmd.isExecutedWhenPreEmpted = False
inputs = cmd.commandInputs
sourceInput = inputs.addSelectionInput(
"SourceBodySelection", "Source", "Please select a source body"
)
sourceInput.addSelectionFilter(adsk.core.SelectionCommandInput.Bodies)
sourceInput.setSelectionLimits(1)
targetInput = inputs.addSelectionInput(
"TargetBodySelection", "Target", "Please select a source body"
)
targetInput.addSelectionFilter(adsk.core.SelectionCommandInput.Bodies)
targetInput.setSelectionLimits(1)
onSelect = MySelectHandler()
cmd.select.add(onSelect)
handlers.append(onSelect)
onUnSelect = MyUnSelectHandler()
cmd.unselect.add(onUnSelect)
handlers.append(onUnSelect)
onExec = MyExecuteHandler()
cmd.execute.add(onExec)
handlers.append(onExec)
except:
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
class MyExecuteHandler(adsk.core.CommandEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
pass
except:
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
class MySelectHandler(adsk.core.SelectionEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
## How can I know which list to add my selection?
pass
except:
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))
class MyUnSelectHandler(adsk.core.SelectionEventHandler):
def __init__(self):
super().__init__()
def notify(self, args):
try:
pass
except:
if ui:
ui.messageBox("Failed:\n{}".format(traceback.format_exc()))