need help simple script

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

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anubis's picture

yes, Max auto-sort them so

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

my recent MAXScripts RSS (archive here)

titane357's picture

hi Anubis, Perhaps for

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] :-(((

AttachmentSize
selection order.png 18.84 KB
Anubis's picture

Then the problem is about

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.

my recent MAXScripts RSS (archive here)

titane357's picture

hello Thanks for help, But

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's picture

Okay, another hint - on FOR

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

my recent MAXScripts RSS (archive here)

real08121985's picture

With this code, if the Array

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's picture

yes, Anubis. In fact I have

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's picture

I see so only Z axis affected

I see so only Z axis affected

my recent MAXScripts RSS (archive here)

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.