View Full Version : how to get vertex id as integer ?

06 June 2003, 09:38 PM
hi, i need the index of a selected vertex of an editpoly as an integer, to use it with setVert and getVert.

i tried this:

getvertselection gives a bitarray so i thought 'findItem polyop.getVertSelection $ 1' would give me the index, but finditem also needs the int i am looking for as an index, i thought it was an array with all selected verts.

??? how to do this, please help.

maybe i have to traverse the bitarray until i get to the selected one? or is there a better way?

06 June 2003, 11:06 PM
findItem <some_array> <item_to_find>

You're passing a bitarray to findItem, which I'm not sure even works. But you don't even need findItem() to get what you're after here. If you're just want the index of a single selected vertex, try using $.selectedVerts[1].index, or (polyOp.getVertSelection $ as array)[1].


06 June 2003, 11:48 PM
thanks for helping out

that seems to be what i need, but are you sure it returns an integer?

I'm working on a script that will help me model morph targets. say you model a smile on the left, and then you want to model that on the right on a new target object. It let's you copy the pos of a vetex then paste it on the coresponding vertex.

still have to manually select the verts and it only works with one at the time for now. i will need to build a list of relations to automate it)

anyway, i'm just starting out on maxscript and could use some help.

i think my reasoning and syntax is correct, but i still get a datatype error. what would be wrong?

the script:


------ morph target modeling helper ------

-- model one side of a morph target, and paste this pose to the other side of a new target
-- (get pos of a vert on one object and paste it to a vertex on another object with same vertlist - ie morph targets)

-- phase 1: manually select the coresponding vertex
-- phase 2: create a list of coresponding vertex id's -- for symmetrical objects! manually/automatically
-- phase 3: add functionality (batch, revert to original pos, 'ripple edit', ...)


-- phase 1 pseudo code : could be simplified if i can get the pos locally

-- (manually) select a vertex on the source object
-- get pos of the vertex [of source object]

-- adjust position relative to object position :

-- compute vert pos relative to pivot origin so we can mirror it (symmetrical aruond local Y axis)
-- the object that will be pasted to is in another place, could be offset in X Y or Z
-- compare and compute to get the new pos

-- (manually) select a - coresponding - vertex on the target object
-- set pos of the vertex [on target object]


global pos = undefined
global sourceObjPos = undefined
global targetObjPos = undefined
global symmetrical_flg = true


function getID =
--local ID = (polyop.getVertSelection $ as array)[1]
local ID = $.selectedVerts[1].index
return ID

function copypos ID =
pos = polyOp.getVert $ ID - $.position

function pastepos ID =
if symmetrical_flg == true then polyOp.setVert $ ID ([-(pos.x), pos.y, pos.z] + $.position)
else polyOp.setVert $ ID pos + $.position


rollout copypaste "copy/paste vertex" width:162 height:146
pickButton picksource "set source object" pos:[8,8] width:144 height:22
pickButton picktarget "set target object" pos:[8,32] width:143 height:22
checkbox chksym "symmetrcial" pos:[72,104] width:80 height:24 checked:true
button copy "get pos" pos:[8,72] width:56 height:27
button paste "set pos" pos:[8,104] width:56 height:27

on picksource picked obj do
sourceObjPos = obj.position
picksource.text =

on picktarget picked obj do
targetObjPos = obj.position
picktarget.text =

on copy pressed do
copypos getID

on paste pressed do
pastepos getID

on chksym changed arg do
symmetrical_flg = arg

myfloater = newRolloutFloater "Target modeler" 210 172

addRollout copypaste myfloater


06 June 2003, 11:58 PM
I can't check that right now (no Max here); seems like both forms should return an integer, though. What are you getting?

--in other words, if you just select a vert and type (polyOp.getVertSelection $ as array)[1] in the listener, what is the result?--


06 June 2003, 12:04 AM
Wow that was fast! :bounce:

how can i see what type it is?

i get this error: "unable to convert: getID() to integer" with both expressions, but it doesn't say what type it is. when i test it in the listener it seems to give a number but i dunno how to be sure.

06 June 2003, 01:38 AM
I see the problem now. When you call a function with no arguments, you need to use parentheses to let it know you're calling the function rather than just listing its value. getID without parentheses doesn't call the function, it just returns getID(), which is obviously not an integer. Use getID() instead.

You may also want to modify your functions so that they take the object as an argument rather than working with '$' directly, and so that they do simple error checking. It's just good practice. So to redefine getID,

fn getID obj =
if classOf obj != Editable_Poly do return false
idx = (polyOp.getVertSelecion obj as array)[1]
if idx == undefined then return false
else return idx

Then, when you call it, do something like this:

id = getID $
if id != false do copypos $ id --with copypos() modded to take an object argument as well

That way, if the object happens to not be an EPoly, or no verts are selected, your script handles it gracefully and doesn't crash or give unpredictable results.

Good luck,

06 June 2003, 01:39 AM
Oh, and to see the type of an object or value (since you asked), use classOf <value>.


06 June 2003, 04:05 AM
:thumbsup: it works now, thanks for the great help!

here it is so far: script (

so basically allows to do now is pasting vertex positions around, but from here i can build to it to [mirror]paste whole poses...

i'l keep you updated...

06 June 2003, 04:15 AM
oh, and thanks for pointing out some basic error checking stuff, leraned a lot from that and the script is more neat indeed with such stuff :bounce:

06 June 2003, 04:12 PM
just wanted to post an update: script (

the script now let's you mirror a pose to another target. for use with morph target modeling.

first select the original - symmetrical!- model, then hit 'build vertex relations'.

then set source and target object where to - mirror -copy pose from/too.

thus you only have to model one side of your facial expressions.

for copying poses the axis checkbox doesn work yet, the model has to be symetrical in X (around XZ plane) and it's pivot centered. also the target copies should be laid out in this direction

WARNING: it's one of my first scripts, and now where finished yet, there little error checking and no undo yet. it's not very neat ui wise either. was just creating something that will help in production and learning some maxscript along the way.

06 June 2003, 12:31 AM
Wow! Looks like you really took the ball and ran ran with it:D

I'll check this out tonight if I get a chance.


06 June 2003, 07:28 PM
cool, please share your thoughts when you do.

i ill add in a feature to copy/paste multiple selected vertices. Also need to work on that undo. pretty odd that doesn't work by itself, it's just a series of commands right? but since i do a loop i will put the whole thing in one undo action after i learned how to do that. beyond that i would look if it is possible to do something like a 'ripple edit' ie when you do (positional) changes to the 'master' mesh, it will update in the targets, optionally keeping the offsets already made in them

but first need to clean it up a bit, my functions could be written better, some are even abundant, and i should think about a more structured error checking.

would it be worth a new thread once i gost so far? since no one else seems to notice this...

07 July 2003, 09:34 AM
Holy crap this I have to check out.

[time passes]

Ah nice, very cool, it works nicely. And, might I add, it works with me just half-assing my way through the interface no less. Brilliant!

Certainly a useful script, and with further iterations to polish off the interface and clean up the code and whatever else you want to do, it should turn out very nicely. Nice work man.

07 July 2003, 11:57 AM
thanks ! It's my first effort at scripting something useful.

07 July 2003, 10:45 PM
hey man this looks like a potentially great and powerful recourse, but I cannot get it to work for more than one vertice at a time. Is there anyway to make it work for multiple vertices?

Anyways thanks and keep up the good work.

07 July 2003, 10:50 PM
I'd like to chime in here as well.

First and foremost I wanted to say thank you for developing a useful script that is open to the community! Now on to my problem...

I have the script installed but cannot get the mirror posing to work.

1) I create an object
2) I copy then mirror that object
3) I edit multiple vertices on the original object.
4) I select the original as "source", and the mirrored copy as "target"
5) With the original object selected I click "build vertex relations"
6) I click "mirror pose to target"

The result? I get an error message : "--Runtime error: Cannot convert value to bitArray: undefined"

Obviously I'm missing something if its working great for others... Where am I screwing up? Someone smack me over the head and help me!

:blush: :wip:

Btw, the setvert and getvert works without a hitch for me, but mirroring only one vert at a time almost defeats the purpose...

I tried running setvert and getvert for one vertex between the source and target because I thought maybe it needed one initial relationship to run the mirror pose, but that also didn't work. Or did I maybe just do it wrong?

Lois Must Die
11 November 2004, 05:58 AM
This is the answer to my prayers. :) Or at least it could be.

I'm an Animation Student currently making morphs, but having trouble getting the 'bl**dy' verts the same on both left and right.

I've never used scripts before and to be honest I'm not keen on 'programming'. But this could save me a real headache.

How do you get it to work?

Do you need to do it before creating the first morph to mirror from?

A little step by step run through of mirroring the morph is really what I'm looking for.

Hope you can help.

Thanks again.


P.S. I hope that discreet pay you a bunch to stick this in Max 8! :thumbsup:

11 November 2004, 07:15 PM
heh, looks like there is some renewed interest in this script eh. This was pretty much my first steps in maxscripting, as experiment and something i needed for a project. Didn't really finish it but i guess i should look into it again, make the basics usable. i'd have to think again how it actually works myself too... i'll have a look about it and see what i can do.

03 March 2005, 06:14 AM
I'm just bumping this thread up for fun.. i wish I could delete my own posts

05 May 2005, 08:38 PM
Here is a working similar script from SCRIPTSPOT.COM

works fine and incredible time saver. good work boys!! :)

CGTalk Moderation
05 May 2005, 08:38 PM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.