SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Home / forum / Animation / Mel Scripts & Programming / position of a vertex
Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 23-06-2007, 06:33 PM   #1
Nirmal_c
Registered User
 
Join Date: Feb 2007
Location: India
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default 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..........
Nirmal_c is offline   Reply With Quote
Old 23-06-2007, 07:12 PM   #2
happymat27
Subscriber
 
happymat27's Avatar
 
Join Date: Jul 2004
Posts: 1,257
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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.
Attached Thumbnails
Click image for larger version

Name:	componenteditor.jpg
Views:	15011
Size:	114.4 KB
ID:	35064  
happymat27 is offline   Reply With Quote
Old 23-06-2007, 07:26 PM   #3
Nirmal_c
Registered User
 
Join Date: Feb 2007
Location: India
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank u....for the fast reply...
Nirmal_c is offline   Reply With Quote
Old 23-06-2007, 07:40 PM   #4
Nirmal_c
Registered User
 
Join Date: Feb 2007
Location: India
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What is the Mel command to get those value...getAttr not working...what is the command????
Please help me!
Nirmal_c is offline   Reply With Quote
Old 23-06-2007, 08:49 PM   #5
happymat27
Subscriber
 
happymat27's Avatar
 
Join Date: Jul 2004
Posts: 1,257
Thanks: 0
Thanked 3 Times in 3 Posts
Default

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.
Attached Thumbnails
Click image for larger version

Name:	positionscript.jpg
Views:	14988
Size:	122.0 KB
ID:	35067  
happymat27 is offline   Reply With Quote
Old 24-06-2007, 05:12 AM   #6
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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


Alan
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 24-06-2007, 04:23 PM   #7
gster123
Moderator
 
gster123's Avatar
 
Join Date: May 2005
Location: Manchester Uk
Posts: 6,300
Thanks: 1
Thanked 51 Times in 45 Posts
Default

Could you not just simpify the script to

xform -q -t -ws;

(with the vertex in question selected before executing the script)
__________________
"No pressure, no diamonds" Thomas Carlyle
gster123 is offline   Reply With Quote
Old 24-06-2007, 05:10 PM   #8
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 24-06-2007, 05:28 PM   #9
gster123
Moderator
 
gster123's Avatar
 
Join Date: May 2005
Location: Manchester Uk
Posts: 6,300
Thanks: 1
Thanked 51 Times in 45 Posts
Default

Suppose so

Just thought that the guy wanted to question one vertex.

Although your script would be great, for a more robust selections
__________________
"No pressure, no diamonds" Thomas Carlyle
gster123 is offline   Reply With Quote
Old 25-06-2007, 01:55 AM   #10
Nirmal_c
Registered User
 
Join Date: Feb 2007
Location: India
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
Nirmal_c is offline   Reply With Quote
Old 20-07-2007, 08:15 AM   #11
Falott
Registered User
 
Falott's Avatar
 
Join Date: Jan 2005
Location: vienna
Posts: 1,095
Thanks: 3
Thanked 20 Times in 18 Posts
Default

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
__________________
everything starts and ends in the right place at the right time.
Falott is offline   Reply With Quote
Old 20-07-2007, 08:47 AM   #12
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

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_";
string $suffix= "_GEO";

string $obj = "pPlane1";
//get a list of our objects, note that this is an array now
string $dupeSel[] = `ls ($stem + "*" + $suffix)`;
int $numbVerts[] = `polyEvaluate -v $obj`;
int $i = 0;

for($i; $i < $numbVerts[0]; $i++)
{

//pick an object to duplicate, by selecting a random int between 0 and the size of the array, Add one to bring it inline with our object IDs that start at 1
int $dupeInt = rand(0, size($dupeSel));
$dupeInt++;


float $pos[] = `xform -q -ws -t ($obj + ".vtx["+$i+"]")`;
//build up a string of which object to duplicate
string $new[] = `duplicate -rr ($stem + $dupeInt + $suffix)`;

setAttr ($new[0] + ".translateX") $pos[0];
setAttr ($new[0] + ".translateY") $pos[1];
setAttr ($new[0] + ".translateZ") $pos[2];

}

Alan
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 20-07-2007, 08:58 AM   #13
Falott
Registered User
 
Falott's Avatar
 
Join Date: Jan 2005
Location: vienna
Posts: 1,095
Thanks: 3
Thanked 20 Times in 18 Posts
Default

woohooo!

that was real fast, thx a lot Alan. Iīll try it right now.
__________________
everything starts and ends in the right place at the right time.
Falott is offline   Reply With Quote
Old 20-07-2007, 09:06 AM   #14
Alan
Moderator
 
Alan's Avatar
 
Join Date: Oct 2002
Location: London, UK
Posts: 2,800
Thanks: 0
Thanked 5 Times in 5 Posts
Default

no worries

Alan
__________________
Technical Director - Framestore

Currently working on: Your Highness

IMDB
Alan is offline   Reply With Quote
Old 20-07-2007, 09:38 AM   #15
Falott
Registered User
 
Falott's Avatar
 
Join Date: Jan 2005
Location: vienna
Posts: 1,095
Thanks: 3
Thanked 20 Times in 18 Posts
Default

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!
__________________
everything starts and ends in the right place at the right time.
Falott is offline   Reply With Quote
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.