batch replace materials

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

Thread Tools Search this Thread Display Modes
Old 01 January 2011   #1
batch replace materials

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 !
Ahmed Yousry

Last edited by Ayousry : 01 January 2011 at 11:49 PM.
Old 01 January 2011   #2
what's matMetalBluef here?
Old 01 January 2011   #3
Thumbs up

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...
Attached Files
File Type: zip (20.9 KB, 5 views)
Old 01 January 2011   #4
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 .
Ahmed Yousry
Old 01 January 2011   #5
That is awesome...

Found this in documentations, I think this is what you exactly want. Try this command:


Dushyant Kumar Kashyap.
Old 01 January 2011   #6
Thread automatically closed

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.
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
Thread Closed share thread

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Society of Digital Artists

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump

All times are GMT. The time now is 12:19 AM.

Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.