PDA

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


SUNCHIRP
11-02-2010, 11: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:

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

SUNCHIRP
11-02-2010, 12:40 PM
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.

http://www.creativecrash.com/maya/downloads/scripts-plugins/utility-external/c/materialrenamer

Regards.

NaughtyNathan
11-02-2010, 12:58 PM
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;
}

:nathaN

SUNCHIRP
11-02-2010, 12:59 PM
Hi, thanks Nathan for the script outline. Always handy. :buttrock:

Regards.

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