position of a vertex
Hi
How to get the value of the position of polygon vertex (x y z)... What is the MEL command to get the value ... Please some one reply me immediately.......... |
1 Attachment(s)
open up the component editor (window > general editors > component editor) select your vert/s and their co-ordinates will show under the poly tab. If you can't see the tab use the scroll arrows that I've highlighted in green.
Hope that helps, Mat. |
Thank u....for the fast reply...
|
What is the Mel command to get those value...getAttr not working...what is the command????
Please help me! |
1 Attachment(s)
This will give you the world co-ordinates of your selected vert
pointPosition OBJECT.vtx[VTX No.]; and this will give you the local co-ordinates of your selected vert. getAttr OBJECT.vtx[VTX No.]; OBJECT is the name of your poly object and VTX No. is the vertex number. My example shows the results for vertex 2 on pCube1. Hope that's what you're after, Mat. |
you have to remember about object space and world space. If you use that getAttr command on the vertex pos you may not always get the worldspace position.
So I would use the xform command (believe me it's your new best friend!) so I would use string $obj = "myObject"; float $pos[] = `xform -q -ws -t ($obj + ".vtx[0]")`; now you can use the array to access the postions: print("pos: " + $pos[0] + " " + $pos[1] + " " + $pos[2]); That's about it really :ninja: Alan |
Could you not just simpify the script to
xform -q -t -ws; (with the vertex in question selected before executing the script) |
well yes you could but why add that extra step into your script? it's less efficient to add in that selection change for EVERY vertex e.g.if you wanted to loop through the verts:
string $obj = "myObject"; int $numbVerts[] = `polyEvaluate -v $obj`; int $i = 0; for($i; $i < $numbVerts[0]; $i++) { float $pos[] = `xform -q -ws -t ($obj + ".vtx["+$i+"]")`; print($obj + ".vtx["+$i+"] " + $pos[0] + " " + $pos[1] + " " + $pos[2] + "\n"); } there's no need to change selection and thus no need to store the users current select to change back to at the end. Alan |
Suppose so
Just thought that the guy wanted to question one vertex. Although your script would be great, for a more robust selections |
Thank for the replies...
I tried out with different changes in xform...its working nice.... Is there any command to verify the changes in attribute....(numerical changes) so that i dont want to assign any specific value in the script. |
I have an additional question to this topic if you guys don´t mind.
I have 8 objects and I want to randomly duplicate and place them at every vertex' position of this base object. what I came up with is string $obj = "body"; string $dupes = "dupes"; int $numbVerts[] = `polyEvaluate -v $obj`; int $i = 0; for($i; $i < $numbVerts[0]; $i++) { float $pos[] = `xform -q -ws -t ($obj + ".vtx["+$i+"]")`; duplicate -rr $dupes; setAttr "dupes.translateX" $pos[0]; setAttr "dupes.translateY" $pos[1]; setAttr "dupes.translateZ" $pos[2]; } this is working for one duplicated object (dupes). but how would I take 8 objects and integrate the randomly duplicated versions of them into this script? tia falott |
rename your 8 objects to use the same stem and suffix that I have listed below, or change those strings to what you want. The suffix is important because you are using a * to match objects, if you dont have a suffix it will match the shape nodes as well and you don't want that. so make sure it's stem_ID_suffix!
Code:
string $stem = "dupes_"; Alan |
woohooo!
that was real fast, thx a lot Alan. I´ll try it right now. |
no worries
Alan |
that was just perfect! after stupid me changed IDs from 0-7 to 1-8. I know you made a comment about that :)
one last question is open for me. is it possible via scripting to align the orientation (let´s say z-axis) of the dupes along the normals of the baseSurface? I mean like the surfaceNormals pointing outwards... or would that be just a ridiculous amount of code to write? besides that - you already made my life a lot easier today! |
Code:
string $stem = "dupes_"; Alan |
goddamnit! I seriously have to get into MEL soon!
thank you and have a nice day! |
I have another question concerning this script. I modified it a littel and it´s allmost working. my aim is to point+orientConstrain an array of objects to another.
this is the code - string $stem = "dupe_"; string $suffix= "_GEO"; string $dupeSel[] = `ls ($stem + "*" + $suffix)`; string $Leaves[] = `ls -sl`; int $selCount = size($Leaves); for($i = 1; $i <=$selCount; $i++) { int $dupeInt = rand(0, size($dupeSel)); $dupeInt++; string $new[] = `duplicate -rr ($stem + $dupeInt + $suffix)`; pointConstraint -offset 0 0 0 -weight 1 ($leaves)($new); orientConstraint -offset 0 0 0 -weight 1 ($leaves)($new); } problem as you might have allready seen - the duped leaves get constrained, but only to the very first object in the list (string $Leaves[] = `ls -sl`; ). probably this command has to be changed, but I don´t know how to make use of all items of that array. I´m really stuck now. tia! |
btw - can anybody tell me some good books or other ressources for starting with MEL. I mean something for really non-logic thinking people like me.
|
well remember that $leaves is an array. So you need to give it an element in the array to constrain to. I'm surprised that using $leaves as you are even works ;)
so you need to do something like pointConstraint -offset 0 0 0 -weight 1 $leaves[5] $new; or you could build up a string like what you have done for the $new variable where you add a suffix and stem to a randomly selected array index. does that make sense? And as for resources I never bought a book or anything like that. Giving yourself projects like this and using the mel script resources are the best ways of learning IMHO Alan |
this
pointConstraint -offset 0 0 0 -weight 1 $leaves[5] $new; would be nice if I just want to take the 5th element out of the array each time I suppose, but when trying to cycle through the complete array (I don´t know ho0w to) I get this error // Error: pointConstraint -offset 0 0 0 -weight 1 ($Leaves[])($new); // // Error: Line 15.50: Syntax error // cause if I put a number into the [] it only constrains 1 element and then stops. it´s allmost the same when just using ($Leaves)($new), where it duplicates correctly but places all dupes onto one single object. I too thought about using "stem" for the selected items. but I have some modeled branches with lots of different leaves with different shaders which I dont want to screw up each time. and as I have to repeat this procedure very often it would be nice to script it over the ls-sl command which is so very handy in this case. I know what you mean Alan by learning with each project. but I am deeply intuitiv thinking. that´s why modeling fits me perfect. but as soon as code comes into place I start over and over again. code doesn´t like me. the above lines took me about 3 hours to get it "kind of" working. thx for your help |
I meant you had to use a variable to randomly select an ID the same way you did above!! You need to do another random int and then use that to pick the correct one from the array.
Dont get disheartened. You'll get it eventually! :D Alan |
HAHA! this one gave me a sleepless night ^^
($Leaves[$i])($new) :D BUT! the only thing is now - the procedure starts with the 2nd item - constrainig them all is fine! but after duplicating the last Leave this one doesn´t get constrained and maya says: // Error: line 15: No object matches name: // guess I have it soon :) |
!!!!!!
($Leaves[$i-1])($new) woohooo! your way of teaching is awesome! |
Hi,
how to get the immediate neighbor of some vertex v ?? please, help me!! |
Code:
global proc string[] getVertexNeighbours() it's untested really but I just wrote it now. :ninja: Alan |
thak u by help, 100% functioned!!!
|
All times are GMT. The time now is 07:16 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Simply Maya 2018