Selection Input

Selection Input

dinocoglitore
Advocate Advocate
1,517 Views
3 Replies
Message 1 of 4

Selection Input

dinocoglitore
Advocate
Advocate

Hi all, I'm having problems with a multiple selection of curves from an Command Dialog.

I din not find any example on the forum or in the documentation so I am asking some help or some example code.

 

These are extracts from the Add-in I'm trying to write:

 

Inside the  SampleCommandCreatedHandler I have this code

.....................

# Create selection input

curve_input = inputs.addSelectionInput('curve_input', 'Select', 'Select curve')

# select only curves

curve_input.addSelectionFilter('SketchCurves')

# I can select more than one curve

curve_input.setSelectionLimits(0)

.....................

 

Inside the SampleCommandExecuteHandler I have this code

.....................

 

# count the number of curves selected

n_selection = inputs.itemById('curve_input').selectionCount

 

# get the curve selected and call helix()

for i in range (0, n_selection 😞

cur = inputs.itemById('curve_input').selection(i)

 

curve = cur.entity

 

# call a function witn the curve selected

helix( curve )

 

 

I do not understand the reason why I receve this error

 

err_screenshot.PNG 

 

 

If I select 3 curves and use the following instruction

cur = inputs.itemById('curve_input').selection(0)

or

cur = inputs.itemById('curve_input').selection(1)

or

cur = inputs.itemById('curve_input').selection(2)

 

 

they do not provide error

 

Someone can help me ?

 

Many Thanks

Dino

 

0 Likes
Accepted solutions (1)
1,518 Views
3 Replies
Replies (3)
Message 2 of 4

ekinsb
Alumni
Alumni
Accepted solution

Selections are somewhat fragile and doing something that changes the database in any way will usually clear any current selections.  I believe that's the problem you're running into here. Whatever your helix command is doing is also having the side effect of clearing the current selection so when you try to get the next entity in the selection it fails.  To work around that you can first get everything from the selection and then do the processing, like shown below.

 

curves = []
for i in range (0, n_selection ):
    curves.append( inputs.itemById('curve_input').selection(i).entity )

for curve in curves:
    helix( curve )

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

dinocoglitore
Advocate
Advocate

Hi Brian, thank you very much for your answer. It obviously solved my problem and make me climb another rung in the kwnoledge of API and Python.

Thanks

Dino

0 Likes
Message 4 of 4

2way3dtext
Contributor
Contributor

Dear kandennti

 

 

0 Likes