View Full Version : set vertices to absolute translateX=0?
Hi everybody,
What I'm trying to do is set all selected vertices to absolute 0 on the X axis.
I'm getting a weird error when I run this script:
// Error: Not enough data was provided. The last 0 items will be skipped. //
Would you mind running the script below and perhaps help me out that way?
//store selected vertices in an array
string $selectedVertices[] = `ls -sl`;
//figure out how many vertices are selected
$arraySize=size($selectedVertices);
print $arraySize;
//for each vertice, snap to 0 on the X axis
for($loops = 0; $loops < $arraySize; $loops++){
setAttr ($selectedVertices[$loops]+".pntx") 0;
}
|
|
BigRoyNL
02-14-2009, 08:45 AM
Running
move -x 0 ;
on selected vertices, like all of sphere, here also snap all of them to the X-axes.. so you wouldn't need to iterate through all of them and apply it seperately. I've had times when I selected multiple and move it to the X-axes to zero that they don't all snap to the X-axes but they snap the middle of all these vertices to the axes.
EDIT:
It's the "Keep spacing attribute". So instead of iterating through selection, your script could turn this off and do it. That would get rid of the whole iterate through process which might be 'longer to calculate'.
// TURNS KEEP SPACING ON
manipMoveContext -e -snapComponentsRelative true Move;
// TURNS KEEP SPACING OFF
manipMoveContext -e -snapComponentsRelative false Move;
Also the arraysize you 'say in the script' that this returns the amount of vertices. That's not true, it returns the amount of 'rows' of vertices'. If you'd select ALL of the vertices of an object it'd return as 1. Selection vertex 1, 2, 3, 4, 18 and 19 would return 2.
Because the array saves it as vtx[1-4] and vtx[18-19].
It IS actually the amount of times you'd have to go through your loop, so you did it correctly, only the comment was wrong.
Also for checking purposes I did this:
string $selectedVertices[] = `ls -sl`;
setAttr ($selectedVertices[0]+".pntx") 0;
Running this on 1 one vertex shows what I does, it runs it, but does nothing. because setting the attribute like this changes the 'x' value of the vertex with 0 relatively. You still have to tell somehow it has to be absolute.
BigRoyNL
02-14-2009, 09:14 AM
Ha.. I'm quite a starte with scripter. Took me some time finding out there was an option 'keep spacing on'.
Glad I could be of any help!
Ha.. WOW, BUG IN THE FORUM.
I replied on your post, but my posts is shown in the topic as if before your post. Or might just be a bug in my browser.
I also found out what is the problem with your script.
Your script WORKS without errors when you select vertices that are not numbered after eachother. So when the array saves out values like vtx[1], vtx[3], vtx[5] it works. But when it does something like vtx[1-3]
Because the setAttr gets confused with the vtx[1-3].
Thank you BigRoyNL!
I can't believe that it was as simple as
move -moveX -absolute 0;
Thank you SO much for the help. It's a bit of a shock for me to work all evening on a script like that- just to have you point out it's as simple as that.
And thanks for the detailed response as well.
wigal
02-15-2009, 08:50 PM
to get it to work with from to numbers in your array [1:200] you can use the -fl flag (flatten) which treats every object in the array individually.
CGTalk Moderation
02-15-2009, 08:50 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.
vBulletin v3.0.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.