View Full Version : UV question.

Haider of Sweden
10 October 2006, 10:18 AM
Hello friends,

I would need help with a MEL solution, that can "fuse" togheter two ore more selected UV points into:

1. the first selected UV point's position
2. the average position of the selected UV points.

Thank you in advance! :)

Haider of Sweden
10 October 2006, 07:05 AM
Could anyone give me some clues - then I might be able to hack something out of it, and learn from some other MELs to create these two solution I was asking for.

I know the command:
polyEditUV -query

But if I select more than one, I can't achieve the average U-V position.
Also, the query doesnt recognize the selection order, so that it can query me the first selected UV point for example.

I will look forward to a reply. :)

10 October 2006, 08:48 AM
the `polyEditUV -q` command returns the 2d UV coords of every selected UV as an array: u1 v1 u2 v2 ... un vn.

so to get the center of all your selected uv's:

float $uv_coord[] = `polyEditUV -q`;
float $centerU=0, $centerV=0;

for ($k = 0;$k<size($uv_coord);$k++)
if ($k%2 == 0)
$centerU += $uv_coord[$k];
$centerV += $uv_coord[$k];
$centerU /= (size($uv_coord)/2);
$centerV /= (size($uv_coord)/2);

print ("U:" + $centerU + " V:" + $centerV);

dont have maya in front of me so it might not work from start :)

oh, and if i remember correctly, the `polyEditUV -q` respects the selection order... try selecting some uvs then run the command and see if the first UV's position matches the first two values splited by the polyEditUV command.

if that command respects the sel order, then the first UV's position should be $uv_coords[0] and $uv_coords[1]. Else, if it does not, then you could use the `filterExpand -sm #masknumber` to get the selected uvs (where #mask number was about 32 or 34 for uv's, don't remember exactly... take a look at the filterExpand docs page for help :D) and then get the first uv's position with `polyEditUV -q uvName`.

Cheers! :)

Haider of Sweden
10 October 2006, 08:31 AM
Yashu, thank you for the first script. It works great!

As for your other tips, they brought me a bit nearer to my target.
This is what I tried:

$uvname = `filterExpand -sm 35`;
print ($uvname[0]);

It seems that filterExpand lists them in the name-order, not selection order.
So if the first one is 22, and second is 12, it gives 12 first, then 22.

How can I get the first selected point?

CGTalk Moderation
10 October 2006, 08:31 AM
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.