ScriptSpot

Forum topic · General Scripting

need help simple script

By titane357 · 2009-07-24

Description

Hello

I "made" a simple script to align poly vertexes to first selected vertex.
But it don't align (always) to first selected vertex...
Dummy is just here to see which vertex is taken for align...
Please if somebody can help....

(
global vertPosition

selectedVert = polyOp.getVertSelection $ as array
vertPosition = polyOp.getVert $ selectedVert[1]
Dummy pos:[vertPosition.x , vertPosition.y , vertPosition.z]
for loopVerts = 1 to selectedVert.count do
(
tempVert = polyOp.getVert $ selectedVert[loopVerts]

polyOp.setVert $ selectedVert[loopVerts] [tempVert.x, tempVert.y, vertPosition.z ]

)

)

Comments (8)

Anubis · 2009-07-25

yes, Max auto-sort them so just collect your wanted vertex separately.

titane357 · 2009-07-25

hi Anubis,

Perhaps for Objects Max keep right order, but if you take a look to the .png, you will see that if I select vertex #5 then vertex #7 or in reverse order, resulting array is the same : [5,7] :-(((

Attachments

Anubis · 2009-07-25

Then the problem is about selection order. Max always return correct order, ie if there is some array: "sel=#(3,5,8)" then sel[1] will be 3, right? But are there sel[1] is the value that we need?... For more clear - to say 5 boxes in the scene and we wont to collect them:

sel = for b in $box* collect b.name
#("Box04", "Box05", "Box06", "Box02", "Box01", "Box03")

-- second line is result, as you see sel[1] will return "Box04" not "Box01". In Max available "sort" fn:

sort sel
#("Box01", "Box02", "Box03", "Box04", "Box05", "Box06")

-- well, now sel[1] will be "Box01". So in your case you must to decide how to collect align vertex.

titane357 · 2009-07-25

hello
Thanks for help,
But in fact after testing, I saw that "selectedVert[1]" is not the first selected vertex but the first vertex in the array which 3dsMax reorder in growing order....

How can I tell Max to return me the first selected vertex ?

Anubis · 2009-07-25

Okay, another hint - on FOR loop you start count from 1 that mean you include 1st vertex also, so the script will try to align 1st vertex to itself. Try to exclude it form the loop startin count by 2 like:

for loopVerts = 2 to selectedVert.count do

real08121985 · 2009-07-25

With this code, if the Array is #(1,3,7), the variable loopVerts will go from 1 to 3, because the arraycount is 3:


for loopVerts = 1 to selectedVert.count do

But you want to go through each item of the array, with this code loopVerts will be 1, 3 and 7:


for loopVerts in selectedVert do

titane357 · 2009-07-25

yes, Anubis.
In fact I have 3 shortcut keys : one for x, one for y and one for z. This script is for z align.
But this script don't always align selected vertexes to the first selected vertex,and I don't understand why,.... :-((

Anubis · 2009-07-24

I see so only Z axis affected