Notifications
Clear all

[Closed] how to get vertex id as integer ?

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?

19 Replies

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].

RH

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

–functions–

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
)


–UI–

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 = obj.name
)

on picktarget picked obj do
(
	targetObjPos = obj.position
	picktarget.text = obj.name
)

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


I can’t check that right now (no Max here); seems like both forms should return an integer, though. What are you getting?

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

RH

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.

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,
RH

Oh, and to see the type of an object or value (since you asked), use classOf <value>.

RH

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…

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:

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.

Page 1 / 2