PDA

View Full Version : help! list the shapenode which is assigned to lambert1


chineseboy
10-22-2011, 12:36 PM
i want create an script that can check my scenes;

if any object is assigned to lambert1,create a new lambert shader assign to them.



anyone can help? thanks a lot !!

Gidsche
10-23-2011, 07:52 AM
Hej...i don`t know if i got you right...therefore i wrote 2 different solutions.....

// Assign a new Lambert for each object with lambert 1


// list all objects in the Scene ( Poly, Nurbs, Subdiv)
string $allShapes[] = `ls -type "mesh" -type "nurbsSurface" -type "subdiv"`;

//loop through all objects
for($shape in $allShapes)
{

string $dest[] = `listConnections -destination true -source false -plugs false -type "shadingEngine" $shape`;

if($dest[0] == "initialShadingGroup")
{
string $newLambert = `shadingNode -asShader lambert`;
string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($newLambert + "SG")`;
connectAttr -f ($newLambert + ".outColor") ($shadingGroup + ".surfaceShader");

sets -e -forceElement $shadingGroup $shape;
}


}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Assign one new Lambert for all objects with lambert1

// Solution with selecting objects
//could be quite heavy in a huge scene

hyperShade -objects lambert1;
string $allLambertObj[] = `ls -sl`;
string $newLambert = `shadingNode -asShader lambert`;
string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($newLambert + "SG")`;
connectAttr -f ($newLambert + ".outColor") ($shadingGroup + ".surfaceShader");
sets -e -forceElement $shadingGroup $allLambertObj

////////////////////////////////////////////////////////////////////

// Solution without selecting objects
//pretty fast

string $initialSGConns[] = `listConnections "initialShadingGroup.dagSetMembers"`;
string $newLambert = `shadingNode -asShader lambert`;
string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($newLambert + "SG")`;
connectAttr -f ($newLambert + ".outColor") ($shadingGroup + ".surfaceShader");
sets -e -forceElement $shadingGroup $initialSGConns;

////////////////////////////////////////////////////////////////////


I hope this works for you....cheers

chineseboy
10-24-2011, 08:58 AM
Hej...i don`t know if i got you right...therefore i wrote 2 different solutions.....

// Assign a new Lambert for each object with lambert 1


// list all objects in the Scene ( Poly, Nurbs, Subdiv)
string $allShapes[] = `ls -type "mesh" -type "nurbsSurface" -type "subdiv"`;

//loop through all objects
for($shape in $allShapes)
{

string $dest[] = `listConnections -destination true -source false -plugs false -type "shadingEngine" $shape`;

if($dest[0] == "initialShadingGroup")
{
string $newLambert = `shadingNode -asShader lambert`;
string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($newLambert + "SG")`;
connectAttr -f ($newLambert + ".outColor") ($shadingGroup + ".surfaceShader");

sets -e -forceElement $shadingGroup $shape;
}


}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Assign one new Lambert for all objects with lambert1

// Solution with selecting objects
//could be quite heavy in a huge scene

hyperShade -objects lambert1;
string $allLambertObj[] = `ls -sl`;
string $newLambert = `shadingNode -asShader lambert`;
string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($newLambert + "SG")`;
connectAttr -f ($newLambert + ".outColor") ($shadingGroup + ".surfaceShader");
sets -e -forceElement $shadingGroup $allLambertObj

////////////////////////////////////////////////////////////////////

// Solution without selecting objects
//pretty fast

string $initialSGConns[] = `listConnections "initialShadingGroup.dagSetMembers"`;
string $newLambert = `shadingNode -asShader lambert`;
string $shadingGroup = `sets -renderable true -noSurfaceShader true -empty -name ($newLambert + "SG")`;
connectAttr -f ($newLambert + ".outColor") ($shadingGroup + ".surfaceShader");
sets -e -forceElement $shadingGroup $initialSGConns;

////////////////////////////////////////////////////////////////////


I hope this works for you....cheers





thanks a million!!


it works!!!

CGTalk Moderation
10-24-2011, 08:58 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.