summaryrefslogtreecommitdiffstats
path: root/tools/MayaTools/Maya4.0/scripts/SimpsonsArt/renameTexture.mel
blob: 4cf0db453d0e915ed4199ba130712f699109eaa4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// renameTexture.mel
// Rename Texture node
// Alias|Wavefront Script File
//
// Creation Date:	20 March. 2001
// Author:		(Novy) Gurdarshan Dhillon
//
//
//
// Description:
//			Renames the texture node to corrisponde to the
//			image file that it contains.  Also outputs the
//			images resolution.
//			
//
//
// Input Arguments:
//			None.
// Return Values:
//			None.
// renameTexture
//


global proc renameTexture()
{
	string $textures[] = `ls -type "file" -type "ramp"`;
	for($texture in $textures)
	{
		string $attr;
		string $image[];
		string $file;
		int $num;
		int $size;
		string $name;
		string $fileNode;
		if (`nodeType $texture` == "file")
		{
			$attr = $texture + ".fileTextureName";
			$file = `getAttr $attr`;
			
			$num = `tokenize $file "/" $image`;
			$num = `tokenize $image[$num-1] "." $image`;
			$attr = $texture + ".outSize";
			float $res[] = `getAttr $attr`;
			print ("\nFile: " + $file + "   " + $res[0] + " × " + $res[1]);
			$size = size($image[0]);
			$name = `substring $image[0] 1 ($size)`;
			$fileNode = `rename $texture ($name + "_t")`;
			print ("\nFileNode: " + $fileNode);
		}
		else if(`nodeType $texture` == "ramp")
		{
			print ("ramp   " + $texture);
			$image[0] = $texture;
			$fileNode = $texture;
		}
		$attr = $fileNode + ".outColor";
		string $shaders[] = `listConnections -d 1 -s 0 -p 1 $attr`;
		// string $shader = $shaders[(size($shaders)-1)];
		for ($shader in $shaders)
		{
			string $info[]; tokenize $shader "." $info;
			if($info[1] == "color")
			{
				$name = $image[0] + "_m";
				string $shadeNode = `rename $info[0] ($name)`;
				print ("\nShading Node: " + $shadeNode);
				$attr = $shadeNode + ".outColor";
				string $engines[] = `listConnections -d 1 -s 0 $attr`;
				for ($engine in $engines)
				{
					$name = $image[0] + "_shg";
					string $engineNode = `rename $engine ($name)`;
					print ("\nShading Engine: " + $engineNode);
				}
			}
		}
		print ("\n----------------------------------------\n");
	}
}

global proc fileRes()
{
	string $textures[] = `ls -type "file"`;
	for($texture in $textures)
	{
		string $attr = $texture + ".fileTextureName";
		string $file = `getAttr $attr`;
		string $attr = $texture + ".outSize";
		float $res[] = `getAttr $attr`;
		print ("\n" + $file + "   " + $res[0] + " × " + $res[1]);
	}
}