View Full Version : Script To Rename Materials To Texture Names ?

11 November 2010, 10:36 AM
Anybody know if there is a script that already exists that takes any number of shaders, queries on the file texture name, say 'tartan.tga', or 'rainbow.tga', and then would rename the material appropriately, i.e. lambert2 becomes tartan, or lambert3 becomes rainbow ?

If not, some guidance with a script would be nice ? :beer:

11 November 2010, 10:54 AM
would u want this applied to the whole scene in one click or from selected materials in the hypershade? or something else?

11 November 2010, 11:40 AM
Hi, thanks for the reply.

I have since managed to find a script on highend / creativecrash that pretty much does what I was looking for, it was to be applied globally.


11 November 2010, 11:58 AM
any given material may have several file nodes attached. how do you decide which to use for the name if there's more than one? just pick the first listed?

this code should work in a basic kinda way just to give you an example of approach, but you would probably want to enhance it and error-check it further in a production setting.

string $shaders[] = `ls -type "lambert"`;
for ($mat in $shaders)
string $files[] = `listConnections -type "file" $mat`;
if (!size($files)) continue;
string $path = `getAttr ($files[0]+".ftn")`;
string $name = `basename $path ""`;
rename $mat $name;


11 November 2010, 11:59 AM
Hi, thanks Nathan for the script outline. Always handy. :buttrock:


CGTalk Moderation
11 November 2010, 11:59 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.