- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi all,
I have multiple selection inputs for my addin. They are designed to hold different selection filters (body & face) and must be separated.
command = adsk.core.CommandCreatedEventArgs.cast(args).command
inputs = command.commandInputs
body_selection = inputs.addSelectionInput('body_selection', 'Select body', 'Click on body to select')
body_selection.addSelectionFilter('Bodies')
body_selection.setSelectionLimits(0)
face_selection = inputs.addSelectionInput('face_selection', 'Select face', 'Click on face to select')
face_selection.addSelectionFilter('Faces')
face_selection.setSelectionLimits(0)
The selections made by users have to be remembered and re-applied next time when users use this command again. Therefore, I stored the selections in two global lists, and used the activate event of command to pre-populate the selections.
global _sel_body, _sel_face
ipts = adsk.core.CommandEventArgs.cast(args).command.commandInputs
#Pre-populate body selections if any
if len(_sel_body) > 0:
body_selection = ipts.itemById('body_selection')
for body in _sel_body:
body_selection.addSelection(body)
#Pre-populate face selections if any
if len(_sel_face) > 0:
face_selection = ipts.itemById('face_selection')
for face in _sel_face:
face_selection.addSelection(face)
To record the selections, I used inputChanged event to detect changes in the selection inputs.
global _sel_body, _sel_face
ipt = adsk.core.InputChangedEventArgs.cast(args).input
if ipt.id == 'body_selection':
_sel_body = [ipt.selection(s).entity for s in range(ipt.selectionCount)]
elif ipt.id == 'face_selection':
_sel_face = [ipt.selection(s).entity for s in range(ipt.selectionCount)]
However, when I tested my code, it did not work as expected (in the pre-populating step, to be precise). First I selected a body and a face for the two selection inputs respectively. Note that the selected face did not belong to the selected body.
After clicking OK, I opened the command again, expecting the same selection (1 body, 1 face) would be made. But instead, 2 bodies & 1 face were selected.
The body of the selected face was selected, although I never selected it. For my understanding, it is because the pre-populating action triggers the inputChanged event.
How can I avoid this behavior? If anyone wants to reproduce this situation, I have attached the addin & the test model in a zip file. Many thanks!
Solved! Go to Solution.