Message 1 of 4
[MEL] A problem in conditions within a for loop

Not applicable
05-25-2020
10:53 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey all, I am writing a material swap script base form a template I found,
Here is my main procedure:
global proc vrayAllLambert()
{
// get selected shaders
//string $sel[] = `ls -sl -st`;
//for ($i=0;$i<size($sel);$i=$i+2)
//get shading engine
string $sg[]= `ls -type "shadingEngine"`;
int $num = size ($sg);
for ( $i=0; $i<$num; ++$i ){
// find shaders have SG
string $mtl[] = `listConnections ($sg[$i] + ".surfaceShader")`;
select -add $mtl;
}
string $allsgMtl[] = (`ls -sl`);
sets -n set_allVRayMtl $allsgMtl;
string $lambert[]= `ls -type "lambert"`;
sets -rm set_allVRayMtl $lambert;
select -r -add set_allVRayMtl;
string $allVrayMtl[] = (`ls -sl`);
//int $num2 = size ($allVrayMtl);
for ($i=0; $i<size($allVrayMtl); $i=$i+2){
if ($allVrayMtl[$i+1] == "VRayMtl")
{
print ("\n");
print ("running Lambert conversion on " + $allVrayMtl[$i] + " hold on tight");
vray2Lambert($allVrayMtl[$i]);
}
else if ($allVrayMtl[$i+1] == "VRayCarPaintMtl")
{
print ("\n");
print ("running Lambert conversion on " + $allVrayMtl[$i] + " hold on tight");
carpaint2Lambert($allVrayMtl[$i]);
}
else if ($allVrayMtl[$i+1] == "VRayBlendMtl")
{
print ("\n");
print ("running Lambert conversion on " + $allVrayMtl[$i] + " hold on tight");
blend2Lambert($allVrayMtl[$i]);
}
}
}
It was working if just select the materials after my update.
And my second update was trying to run it globally in the scene (line7-22).
It ran without an error, but seems it didn't pick up the second for loop in line 26 anymore.
I have print a message in those conditions, none of that print out....
My guess is the $i, please help, thanks!