I can't get this working, if I remove the break the script works, but it creates too many erroneous groups, with the break in there it creates a single group, but then when I run the script again it ignores the if statement? Any idea what I'm doing wrong?
string $transforms[] = `ls -tr`;
for ($t in $transforms) { if ($t == "null1") { delete $t; print "Deleted group."; }
Thanks for your reply, the file is an empty scene, we were able to figure out my problem. Here is the code that works, I needed to put a switch in there to test the if statement and set it to true or false, would be nice if you could use operators like ! on strings, but whatever this works now.
Replies
To help with the debug you could make your print statement print the $t variable so you can see what it's doing when it creates the group.
int $switch = 0;
string $transforms[] = `ls -tr`;
for ($t in $transforms)
{
if($t == "null1")
{
delete $t;
$switch = 1;
print "Delete.";
break;
}
}
if($switch == 0)
{
CreateEmptyGroup;
print "Created.";
}
if you use one of the string comparison functions it can handle that a bit more robustly.
https://download.autodesk.com/global/docs/maya2014/en_us/Commands/gmatch.html
https://download.autodesk.com/global/docs/maya2014/en_us/Commands/strcmp.html
https://download.autodesk.com/global/docs/maya2014/en_us/Commands/match.html
for example this is the same as using != :