Friday, 25 March 2011

Texture Path Rename Script

Here's just a script that deletes everything infront of the sourceimages in the file texture path and then save it as an ASCII file.

If the texture path reads: "C:/Users/Project/sourceimages/texture.jpg"
It changes it to : "//sourceimages/texture.jpg"

When the right project is set, the texture can be found by maya, regardless on what computer your working on.

global proc PS_texture_path_rename(){

// find all the textures in the scene

string $tex[] = `ls -textures`;

string $newPath;

for($each in $tex){

// get the file texture path

string $path = `getAttr ($each + ".ftn")`;

// converts the path in to a string array

string $array[] = stringToStringArray($path, "/");

// get the size of the array

int $size = size($array);

// create the new path by deleting everything but the souceimages and the file name

$newPath = "//"+$array[$size-2]+ "/" +$array[$size-1];

// set the new path to the texture

setAttr -type "string" ($each+".fileTextureName") $newPath;

}

// save the file as a maya ASCII

file -f -save -options "v=0" -type "mayaAscii";

}