I'm writing a simple script for my wife, when I click this button it checks to see if one of the UV sets is named lightmap and should producer an error and stop. If it doesn't find light map it should run the second part of the script. For some reason even when light map exists as a UV set it runs the error, but then also runs the else statement. What am I doing wrong? It's like it finds both statements to be true.
$danaUVs = `polyUVSet -q -auv`;
for ($danaSet in $danaUVs) { if ($danaSet == "lightmap") { updateUvSetEditor; error "lightmap UVs already exist";
ok the problem is that you're applying the if statement to each part of the array of UV's.
This is a modified version that only does something after you've checked each uv set
global proc uvsetTest()
{
string $danaUVs[] = `polyUVSet -q -auv`;
int $lightMapExists = 0;
//this bit checks if lightmaps exists
for ($danaSet in $danaUVs)
{
if ((`gmatch $danaSet "lightmap*"`) == 1)
{
//updateUvSetEditor;
error "lightmap UVs already exist";
$lightMapExists = 1; //when a lightmap is found the variable is set
}
}
//then if they don't exist this does something
if ( $lightMapExists == 0){
polyCopyUV -uvSetNameInput "map1" -uvSetName "lightmap" -createNewMap 1 -ch 1;
toggleSelMode;
toggleSelMode;
selectMode -object;
print "Lightmap UVs created";
}
}<br>
Replies
This is a modified version that only does something after you've checked each uv set
http://download.autodesk.com/us/maya/2009help/Commands/gmatch.html
So the way I've used gmatch it matches with lightmap1 or lightmap2 or lightmap365