Hello, long time checking this website and after a while of being stuck (3 days) I thought about asking directly here.
I am new with MEL, i hardly know what I’m doing, so I check scripts online from other people that has similar problems, but yet I haven’t found a solution. This is what I’m trying to achieve:
Change all lambert materials to redShift materials.
What I could achieve so far:
Make the redshift material and connect the texture node from the lambert to the redShift material.
What I need to finish:
Assign the material to its respective object. This I could do, but the problem is that it selects the objects in order and then it doesn’t assign the materials properly.
select -r `listTransforms -geometry`;
string $selection[] = `ls -selection -long`;
/* loop through all objects */
string $object;
int $contador = 0;
string $nomObjecte = ("RedShift" + $contador);
int $jaHePassat = 0;
// list/get all lambert-based shaders in the scene
string $shaders[] = `ls -type "lambert"`;
for ( $object in $selection )
{
// iterate through each shader in the array:
if ($jaHePassat == 0)
{
for ($item in $shaders)
{
// find out what is connected to the shaders "color" attribute
string $colorTex[] = `listConnections ( $item + ".color" )`;
// if nothing conncted, ignore:
if (!`size $colorTex`) continue;
// create a node of type "gammaCorrect"
string $gammaNode = `shadingNode -asShader RedshiftArchitectural`;
string $SG = `sets -renderable true -noSurfaceShader true -empty -name $nomObjecte`;
// connect this gamma node between texture and shader:
connectAttr -f ( $colorTex[0] + ".outColor" ) ( $gammaNode + ".diffuse" );
connectAttr -f ( $colorTex[0] + ".outAlpha" ) ( $gammaNode + ".transparency" );
connectAttr -f ( $gammaNode + ".outColor" ) ( $SG + ".surfaceShader" );
$jaHePassat = 1;
}
}
sets -forceElement $nomObjecte $object;
$contador = $contador + 1;
$nomObjecte = ("RedShift" + $contador);
}
I’ll gladly answer any questions regarding the code, thanks ina dvance for reading this.