MEL How-To #56

Back · Previous · Next Maya

How do I determine which UV Set is being used to derive the UVs for the Texture of a given face component?

Given a textured polymesh face component, there are five steps to determine the UV Set used to derive its UVs:

  1. Determine the Shading Group used to shade the face.

  2. Trace this upstream to the Material providing the ‘.surfaceShader’ input for the Shading Group.

  3. Trace this upstream to the Texture providing the ‘.color’ input for the Material.

  4. Find the attribute plug for the corresponding UV Set which is linked to this Texture.

  5. Query the name of the UV set from this plug.

The first three steps can be accomplished using:

These are all described in the How-To: The ‘uvLink’ MEL command is used to determine the relationship between a Texture and a UV Set. You may query the relationship for all UV Sets or for the UV Set in a specific object. To perform the latter, specify the −queryObject flag with the uvLink command.
string $object = "pSphere1";

string $texture = "myTexture";  // example, as returned from getTextureFromMaterial()

string $uvSetPlug[] = `uvLink -queryObject $object -texture $texture`;
// Result: pSphereShape1.uvSet[0].uvSetName //

By my observations UV Set linking is mutually exclusive. Linking a UV Set to one Texture (or linking a Texture to a UV Set) will unlink any previous relationship. Thus you may expect there to be a 1:1 relationship. In short, if you query a uvLink for a single object you will get only one ‘.uvSetName’ in return.

The last step is to query the plug returned by ‘uvLink’ to get the name of the UV Set:

getAttr $uvSetPlug[0];
// Result: map1 //

Related How-To's

Tuesday, October 09, 2001