[Closed] Adding constraints in listbox
Hello friends, I’m trying to get edge constraints to work in my rollout, however I am unable to figure out how to make the listbox work correctly.
The code I have so far looks like this:
group “Edge Constraint Options”(
combobox edgeConstraint “Constraints” items:#([0],[1],[2],[3], “None”, “Edge”,“Face”,“Normal”)
(
on edgeConstraint do(
$.constrainType = edgeConstraint.array
)
)
)
The logic I’m trying is very simple. I want $.constraintType = either 0,1,2,3. I figured using an array index would work, however it doesn’t appear to be this simple.
How do I fix this?
Many thanks
rollout combobox_test "Combo Box"
(
group "Edge Constraint Options"
(
combobox edgeConstraint "Constraints" items:#("None", "Edge","Face","Normal")
)
on edgeConstraint selected i do
(
for o in selection where classOf o == Editable_Poly do
(
o.constrainType = (i - 1)
)
)
)
createDialog combobox_test
Thanks so much!
Can you explain what the loop is doing?
How does the combobox know what the items are in relation to it’s position (0-3)?
The loop is for all selected Editable poly objects. So you can change the edge constarint for all of them. To test it create few spheres, convert them to Editable Poly, select them and use the script. Then check the Edge constraint for each sphere.
How does the combobox know what the items are in relation to it’s position (0-3)?
From maxscript help file
**on <combobox> selected <arg> do <expr>**Called when the user selects an item in the combo box list. The <arg> argument contains the new current selection item number.
So here on edgeConstraint selected i do
the i
is the arg
from the help file. Since the Edge constarints starts from 0 to 3, the (i – 1) has to be used(because arrays in maxscript is 1-based).