View Full Version : n00b pointPosition Project

03 March 2009, 02:57 PM
Hey guys and gals,

Here's the story spiel;
I'm an artist with very little MEL experience but a fair bit of common sense... (I hope)
We just had a new starter arrive who mostly used MAX, and today asked me how he finds out the world co-ordinates of a selected vert.
A little research and I found the pointPosition command which produced the required info for him.

Anyway, I like to dabble in little bits of code here and there, and anything that adds/changes my standard maya shelf is always a plus. So I thought I'd set myself a little project and maybe you fine fine people can help me along the way?

What I'd like to do is create a MEL script that produces a floating window which simply displays the XYZ of the currently selected vert, in seperate, easy to read boxes.

Kind of like this;
¦Vert Location¦
¦X ¦ 000.000 ¦
¦Y ¦ 000.000 ¦
¦Z ¦ 000.000 ¦

So in essence I want the script to create the window with a table;
Perform the pointPostion action and print those three co-ordinates in the three boxes;
I'd kind of like the window to update itself anytime a vert is selected? I guess maybe this would be done using a scriptJob maybe?

Anyway, not in a rush, just something I'd like to look into. Any help much appreciated.
Thanks all.

03 March 2009, 04:55 PM
just to note that if you want to script this you MUST perform an action (push a button) so the script calculates the info you need. So you must do a plugin for that, so it calculates it everytime. The workaround would be to use a script job (as you mentioned), that always updates your script, but I wouldn't recommend that.

03 March 2009, 09:22 AM
There's nothing wrong with using scriptJobs as long as they're simple and you don't go crazy with hundreds of them. Something like this task is very simple and is perfectly safe as a scriptJob imho.

And here ya go!

This will work as long as you have just 1 vertex selected, otherwise the window doesnt' udpate.
global proc vertPosWindow()

if(`window -exists vertPosWindow` )
deleteUI vertPosWindow;

string $sWindow = `window -title "Vert Position" vertPosWindow`;
floatFieldGrp -l " X:" -cw 1 25 vertPosXField;
floatFieldGrp -l " Y:" -cw 1 25 vertPosYField;
floatFieldGrp -l " Z:" -cw 1 25 vertPosZField;
setParent ..;
showWindow $sWindow;
global int $g_nVertPosWindowJob;
scriptJob -k $g_nVertPosWindowJob;
$g_vertPosWindowJob = `scriptJob -e "SelectionChanged" vertPosWindowUpdate`;

global proc vertPosWindowUpdate()
string $saSelection[] = `ls -sl`;
if(size($saSelection) == 1)
string $saTemp[];
if($saTemp[1] == "vtx")
float $faPos[] = `pointPosition -w $saSelection[0]`;
floatFieldGrp -e -v1 $faPos[0] vertPosXField;
floatFieldGrp -e -v1 $faPos[1] vertPosYField;
floatFieldGrp -e -v1 $faPos[2] vertPosZField;



03 March 2009, 09:56 AM
yea can't understand why a scriptJob wouldn't do the job here.

hey dbiggs. Sorry to rip your code apart, had some ideas to improve this :wise: hope you don't mind ;]

parent the scriptJob directly > no worry about id
call vertPosWindowUpdate on window creation
added vertPosWindowChange to reflect changes on any selected vertices
greyed out window if no vertices are selected.
used filterExpand in vertPosWindowUpdate to speed up evaluation
global proc vertPosWindow()
if(`window -exists vertPosWindow` )
deleteUI vertPosWindow;

window -title "Vert Position" -s 0 -toolbox 1 vertPosWindow;
columnLayout vertPosColumn;
floatFieldGrp -l " x:" -cw 1 25 -precision 3 -dc "vertPosWindowChange x #1" -cc "vertPosWindowChange x #1" vertPosXField;
floatFieldGrp -l " y:" -cw 1 25 -precision 3 -dc "vertPosWindowChange y #1" -cc "vertPosWindowChange y #1" vertPosYField;
floatFieldGrp -l " z:" -cw 1 25 -precision 3 -dc "vertPosWindowChange z #1" -cc "vertPosWindowChange z #1" vertPosZField;
setParent ..;
showWindow vertPosWindow;

scriptJob -e "SelectionChanged" vertPosWindowUpdate -parent vertPosWindow;


global proc vertPosWindowUpdate()
string $vtxs[] = `filterExpand -sm 31 -expand 1`;
float $pos[3];
columnLayout -e -en 1 vertPosColumn;
$pos = `pointPosition -w $vtxs[0]`;
floatFieldGrp -e -v1 $pos[0] vertPosXField;
floatFieldGrp -e -v1 $pos[1] vertPosYField;
floatFieldGrp -e -v1 $pos[2] vertPosZField;
columnLayout -e -en 0 vertPosColumn;

global proc vertPosWindowChange(string $axis, float $value)
move("-ws","-" + $axis, $value);

someone ideas for more? i love sh!t like that :thumbsup:
the precision doesn't change the Ctrl+clickdrag speed :/ 1.0 minimum is waaaay to much to work with that.

03 March 2009, 11:58 AM
Why don't you take a look at the code for the Component Editor Window? It should be located inside your Maya installation directory. It pretty much does the same things you want, only it gives up whole lot more values than you might require. You can go around and hack it as you please (Just take a back up copy first). Hope that helped...


03 March 2009, 09:39 AM
Heh I don't mind you modifying my code ewerybody.

Some nice changes and additions there. In my defense, I wasn't going for a full featured app, it was just enough to to what Beillzibub asked :)

03 March 2009, 11:41 AM
Why not use a headsUpDisplay??? Looking at the headsUpDisplay-command in the Maya-Doc I changed the example like this:

global proc float[] vertexPosition ()
string $selectedVerts[] = `ls -sl -fl`;
float $position[3];
if (size($selectedVerts) > 0)
string $vertex = $selectedVerts[0];
$position = `xform -q -ws -t $vertex`;
$position[0] = 0;
$position[1] = 0;
$position[2] = 0;
return $position;

headsUpDisplay -section 1
-block 0
-blockSize "medium"
-label "Position"
-labelFontSize "large"
-command "vertexPosition()"
-event "SelectionChanged"
-nodeChanges "attributeChange"

Cheers ;)

03 March 2009, 12:15 PM
Ahh gee guys, you lot are great!
I really didn't expect so many ideas and actual work to be done on this. Thank you so much!
A few pointers and such I would have been great, but you've truly gone above and beyond.

CGTalk Moderation
03 March 2009, 12:15 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.