FORUMS: list search recent posts

Mel Script - loop

COW Forums : Autodesk Maya

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Jose Francisco Tarallo
Mel Script - loop
on Apr 11, 2011 at 9:28:13 pm

Hi everyone.
I'm stuck with a simple script:
--------
//variables
string $sel[] = `ls -sl`;
int $iSel;

//loop

for ($iSel=0; $iSel < size($sel); $iSel++){

string $imgNode[] = `defaultNavigation -dtv -d ($sel[$iSel] + ".outColor")`;

print (" counter = " + $iSel + "n");
print ($imgNode[$iSel] + "n");
print ($sel[$iSel] + $oColor + "n");
print ("n" + "n");

}


-------

the problem is that it returns:

////////////
counter = 0
imgCube3
sShaderCube3.outColor


counter = 1

sShaderCube1.outColor


counter = 2

sShaderCube2.outColor

///////////////
it just returns the first img node of the selection.

Can anyone help me?


Return to posts index

Steve Sayer
Re: Mel Script - loop
on Apr 21, 2011 at 3:46:34 pm

Each time you assign a value to $imgNode it overwrites the old values. I assume this is okay, and you don't actually want it to increase as an array; you just have to use an array because of the return type of the defaultNavigation command.

So, when you print the value of $imgNode you should just print $imgNode[0] every time; don't increment the index argument because you're not ever storing anything beyond that first index. Returning $imgNode[1], [2], [3] and so on just returns empty strings.

Hope that helps.

-Steve


Return to posts index

Jose Francisco Tarallo
Re: Mel Script - loop
on Apr 21, 2011 at 4:09:09 pm

yes, you are right.
I was trying to use the $imgNode variable as the others, but like you said... it will be always [0].

i finished the script.
Its for change the surface shader nodes to Lambert.
it gets the color texture of Surface Shader and link it to the new Lambert.
it's simple but can be useful...

the only thing now is that we need to select the surface shaders nodes on Hypershader.
i was trying to make it automatic changing the $sel line to "string $sel[] = `ls -mat`;" but it returns an error when it doesnt find the color node.
But it works fine for now. it will be the next step.

thanks a lot.

the script>>
-------------------------------

string $sel[] = `ls -sl`;
int $i;
string $imgNode[] ;

//loop

for ($i=0; $i < size($sel); $i++ ){
$imgNode = `defaultNavigation -dtv -d ($sel[$i] + ".outColor")`;
disconnectAttr ($imgNode[0] + ".outColor") ($sel[$i] + ".outColor");
createNode -n("mat" + $i) lambert;
replaceNode $sel[$i] ("mat" + $i);
connectAttr -force ($imgNode[0] + ".outColor") ("mat" + $i + ".color");
delete $sel[$i];


}


Return to posts index


Steve Sayer
Re: Mel Script - loop
on Apr 21, 2011 at 5:22:41 pm

What about using "ls -type lambert" to get the list?

A problem seems to be that phongs (and perhaps other materials?) count as both 'lambert' AND 'phong' types. A possible solution would be to list (or select) all lamberts, then subtract from that list all phongs (and other overlapping node types).

select -r `ls -type lambert`;
select -d `ls -type phong`;
string $lamberts[] = `ls -sl`;


Thanks for sharing the script!

-Steve


Return to posts index

Jose Francisco Tarallo
Re: Mel Script - loop
on Apr 21, 2011 at 8:05:35 pm

Yeah, i understand. But even with any type of material, if the "outColor" Attr is empty it return an error. i think the path could be some "if ($imgNode == "") { do nothing } ...
"" = empty.
and im new at mel script and i dont know how to make it to do nothing at that loop.
is there some 'return' or 'go to line' command?

tx,
Jose


Return to posts index

Steve Sayer
Re: Mel Script - loop
on Apr 21, 2011 at 11:05:05 pm

Ah, I think I see now.

Yeah, if you try to navigate along a connection that doesn't exist, you'll get an error.

I think the solution is to test whether or not it's connected first, then navigate only if it is. I think the 'isConnected' command will be helpful here... but I don't have time to test at the moment.

-Steve


Return to posts index


Jose Francisco Tarallo
Re: Mel Script - loop
on Apr 25, 2011 at 2:11:24 am

I've made some changes and i think its better now.
take a look:

remember that the switch will be done only on Surface Shaders that has imagens linked on outColor. Now you dont need to select the nodes.

*********************************************

string $sel[] = `ls -type surfaceShader`;
int $i;
string $imgNode[] ;


//loop

for ($i=0; $i < size($sel); $i++ ){

if (`connectionInfo -isDestination ($sel[$i] + ".outColor")`) {

$imgNode = `defaultNavigation -dtv -d ($sel[$i] + ".outColor")`;
disconnectAttr ($imgNode[0] + ".outColor") ($sel[$i] + ".outColor");
createNode -n("mat" + $i) lambert;
replaceNode $sel[$i] ("mat" + $i);
connectAttr -force ($imgNode[0] + ".outColor") ("mat" + $i + ".color");
delete $sel[$i];

} else {
print ($sel[$i] + " - no image" + "\n") ;
}

}


Return to posts index

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
© 2017 CreativeCOW.net All Rights Reserved
[TOP]