Notifications
Clear all

[Closed] Store selected vertices in Array

Hi everybody.

Once again, i have a new question:
I just want the User to specify some verts. And after that, click on a button and the verts should be moved to a certain position. But i don’t know what commands to type in, if i want to store the selected verts in an array so i can move them step by step.

thanx
cheers

7 Replies

vertex_array[vertex_array.count+1] = newly_selected_vert

–array name [array length + 1 to create new entry in array] = the new vert you’re adding

but how do i find out, what verts the user has selected?

the script is supposed to be executed after the user has selected the verts. Can’t i just write something like this:

selection_array = #()
for i = 1 to selection.count do
(
selection_array[i] = selection[i]
)

This works fine for objects, and i was hoping that it also would work with verts, when i am in vertex mode, but it doesn’t.
Any clue?

Hey mlanser, to loop through the selected verts you can do something like this:

vertselection = polyop.getVertSelection $.baseobject
for i in vertselection do
(
polyop.setVert $.baseobject i newposition node:$
)

thank you very much. that’s gonna help me out.

but now i have a new question:
how can i get the coordinate of a selected vert?

Okay, found that out by myself:

But the function you’ve mentioned works only, when i want to move all selected verts to the same coord, specified in newposition.

I wanted to move each one of them to an own position, specified in an array like this;

newposition = #([-9.03285,4.27292,65.1078],
[-8.05216,4.04474,65.7208],
[-10.0686,4.49353,64.5844],
[-11.1753,4.66483,64.3004])

But when i use this function here, 3ds max tells me that this is not possible: undefined in type: Point3.
The function works, when i change newposition[i] to newposition[1]. And i don’t think that this is some kind of out of Array error, since i select always just as much verts as specified in the newposition-array, which means in this example 4.

vertselection = polyOp.getVertSelection $.baseobject

for i in vertselection do
(
polyop.setVert $.baseobject i newposition[i] node:$
)
Any clue?

Okay, found that also by myself.

i didn’t know that i isn’t numerated continously but has the vert-numbers of the object.
i changed that with this function:

for i in vertselection do
(
polyop.setVert $.baseobject i newposition[j] node:$
j=j+1
)

Cheers

Hey, yeah you can do it like that or, since you have the same amount of positions in your array as vertices to set, do something like this:

vertselection = polyop.getVertSelection $.baseobject as array
selcount = vertselection.count
for i = 1 to selcount do
(
polyop.setVert $.baseobject vertselection[i] newposition[i] node:$
)

In this case “i” will be counted from 1 to the selected verts count instead.

Another option could be to do it all in the same loop if possible. This example would move each vert 10 units in the world z direction:

vertselection = polyop.getVertSelection $.baseobject
for i in vertselection do
(
currentpos = polyop.getVert $.baseobject i node:$
newpos = currentpos + [0,0,10]
polyop.setVert $.baseobject i newpos node:$
)