PDA

View Full Version : batch replace materials


shoox
01-21-2011, 11:46 PM
Hey guys ,

i have a scene file imported from max that has tones of phong materials and i wanna batch replace all the materials to Lambert .

string $shaderNode = "material name here . .";
string $replaceWith = `createNode "lambert"`;
replaceNode $shaderNode $replaceWith;
delete $shaderNode;
rename $replaceWith $shaderNode;

this script is working fine however every time i try to run a for loop on this it does`t work ;
here is the one with the for loop

string $sel[] = `ls -sl`; string $use;
for ($use in $sel){
string $shaderNode = "matMetalBluef";
string $replaceWith = `createNode "lambert"`;
replaceNode $shaderNode $replaceWith;
delete $shaderNode;
rename $replaceWith $shaderNode;
}


Any help will be greatly appreciated !
thanks,

dushyantk
01-22-2011, 10:03 AM
what's matMetalBluef here?

dushyantk
01-22-2011, 10:22 AM
Ok, got it, but This code works well with me, I've three objects with one blinn "matMetalBluef" assigned to all of'em, but if you have different objects with different materials assigned to each object, this code might not work.

Also, there's one more issue with this code, it replaces only material node, so now wrong material node is attached to wrong shadingGroup node.

Download the file attached and run your code and tell me what exactly you want... :thumbsup:

shoox
01-23-2011, 10:54 AM
hey dushyantk
my script only work with one material, it doe`t work when u select multiple materials .
my scene has tones of materials that imported from max and they all come with high reflective phong shaders .

dushyantk
01-25-2011, 06:21 AM
Found this in documentations, I think this is what you exactly want. Try this command: :thumbsup:

deleteShadingGroupsAndMaterials;

...

CGTalk Moderation
01-25-2011, 06:21 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.