指定贴图路径汉化版

脚本名称:FileTextureManager

脚本语言:MEL

脚本来源:劲暴羊工具盒

汉化说明:

这个Maya指贴图工具其实功能非常强大,我是从劲暴羊工具盒知道的这个脚本,为了使用这个工具更方便,所以汉化了这个脚本;在一段时间的使用后,没发现有问题。分享给有需要的人。如果使用发现有什么问题,请使用未汉化原版本;

汉化界面

汉化版源码:

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
//工具名称:FileTextureManager(文件纹理管理器)
// 汉化:三岁豆

//定义选择程序

proc int FTM_SelCheck(string $nodes[]){
int $sel = 0;
if (size($nodes))
$sel = 1;
else
confirmDialog -t "File Texture Manager" -m "必须至少选择一个文件纹理节点!" -b "OK";
return $sel;
}


// 提醒用户作业已完成的进度。

proc FTM_END(){
confirmDialog -t "File Texture Manager" -m "操作已完成。\n作业已完成。" -ma center -b "OK";
}


//日志

proc FTM_Log (string $type, string $node, string $log) {
string $finLog;
if (size($node))
$log = $node + "\n";
else
$log = "\t" + $log + "\n";
switch ($type) {
case "start":
$finLog = "\n***************************************************************************************************************\n\
File Texture 管理器日志启动\n\
***************************************************************************************************************\n";
break;
case "end":
$finLog = "***************************************************************************************************************\n\
File Texture 管理器日志结束\n\
***************************************************************************************************************\n";
break;
default:
$finLog = $log;
break;
}
print $finLog;
}


// 获取正确的路径(文件夹)格式以匹配当前操作系统。

proc string FTM_GetPath (string $FTM_FileOrPath, string $FTM_OldPath)
{
$FTM_OldPath = `substituteAll "\\\\" $FTM_OldPath "/"`;
if ($FTM_FileOrPath == "file")
$FTM_OldPath = `dirname $FTM_OldPath`;
$FTM_OldPath = `substitute "/*$" $FTM_OldPath ""`;
string $FTM_RightPath;
if (size($FTM_OldPath)) $FTM_RightPath = `toNativePath ($FTM_OldPath + "/")`;
return $FTM_RightPath;
}



//获取与当前操作系统匹配的输入文件全名(包括路径)的正确格式。
//返回一个字符串数组,第一个元素是输入文件的正确格式
//全名(包括路径),第二个元素是输入文件的短名称(没有路径)。

proc string[] FTM_GetFile (string $FTM_OldFullPath)
{
string $FTM_RightPath[];
string $FTM_PathElements[];
int $FTM_PathElementsSize;
// fullname
$FTM_OldFullPath = `substituteAll "\\\\" $FTM_OldFullPath "/"`;
$FTM_RightPath[0] = `toNativePath $FTM_OldFullPath`;
$FTM_PathElementsSize = `tokenize $FTM_OldFullPath "/" $FTM_PathElements`;
$FTM_RightPath[1] = $FTM_PathElements[$FTM_PathElementsSize - 1];
return $FTM_RightPath;
}


//分析当前场景中的所有文件纹理节点。
//
proc string[] FTM_FileTextureAnalyst ()
{
global string $lsCmd;
string $FTM_Files[] = eval($lsCmd);

// Different groups.
string $FTM_Groups[];
int $FTM_GroupsSize;
if (size($FTM_Files)){
$FTM_Groups[0] = "FTM_EmptySocket_FTM";
$FTM_Groups[1] = "FTM_MissingPathSocket_FTM";
}

for ($eachFile in $FTM_Files)
{
$FTM_GroupsSize = size($FTM_Groups);
string $FTM_CurrentFullPath = substituteAll ("\\\\", `getAttr ($eachFile + ".fileTextureName")`, "/");
string $FTM_CurrentPath = dirname ($FTM_CurrentFullPath);

if (size($FTM_CurrentPath))
{
for ($j=2; $j<$FTM_GroupsSize; $j++)
{
string $buffer[];
tokenize $FTM_Groups[$j] "*" $buffer;
string $FTM_OldPath = $buffer[0];
string $cmp1 = $FTM_CurrentPath;
string $cmp2 = $FTM_OldPath;
if (`about -nt`) {
$cmp1 = tolower($FTM_CurrentPath);
$cmp2 = tolower($FTM_OldPath);
}

if ($cmp1 == $cmp2)
{
string $tmp = $FTM_Groups[$j];
$tmp += "*" + $eachFile;
$FTM_Groups[$j] = $tmp;
break;
}
}

if ($j >= $FTM_GroupsSize)
{
$FTM_Groups[$FTM_GroupsSize] = $FTM_CurrentPath + "*" + $eachFile;
continue;
}
}
else if (size($FTM_CurrentFullPath)){
string $tmp = $FTM_Groups[1];
$tmp += "*" + $eachFile;
$FTM_Groups[1] = $tmp;
}
else{
string $tmp = $FTM_Groups[0];
$tmp += "*" + $eachFile;
$FTM_Groups[0] = $tmp;
}
}

select -cl;
return $FTM_Groups;
}


//生成UI控件

proc FTM_EditUIControl (string $FTM_OptionColumn, string $FTM_HelpForm)
{
// Operation mode
radioButtonGrp -e -on1 ("textFieldButtonGrp -e -en 0 -tx \"\" " + $FTM_OptionColumn + "|FTM_SourceDirectoryField")
-on2 ("textFieldButtonGrp -e -en 1 -tx \"\" " + $FTM_OptionColumn + "|FTM_SourceDirectoryField")
($FTM_OptionColumn + "|FTM_OperationMode");
// Set source directory
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"file\" \"" + $FTM_OptionColumn + "|FTM_SourceDirectoryField\" \"Set_S.D.\" 0")
($FTM_OptionColumn + "|FTM_SourceDirectoryField");
// Set target directory
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"path\" \"" + $FTM_OptionColumn + "|FTM_TargetDirectoryField\" \"Set_T.D.\" 4")
($FTM_OptionColumn + "|FTM_TargetDirectoryField");
// Make new folder
checkBoxGrp -e -on1 ("textFieldGrp -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_NewFolderNameField")
-of1 ("textFieldGrp -e -en 0 -text \"MyTextureFiles\" " + $FTM_OptionColumn + "|FTM_NewFolderNameField")
($FTM_OptionColumn + "|FTM_MakeFolderChecker");
// Add prefix
checkBox -e -onc ("textField -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField")
-ofc ("textField -e -en 0 -text \"prefix_\" " + $FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField")
($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_AddPrefixChecker");
// Add suffix
checkBox -e -onc ("textField -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField")
-ofc ("textField -e -en 0 -text \"_suffix\" " + $FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField")
($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_AddSuffixChecker");
// Replace string
checkBoxGrp -e -on1 ("textFieldGrp -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_OldStringField; textFieldGrp -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_NewStringField")
-of1 ("textFieldGrp -e -en 0 -text \"OldString\" " + $FTM_OptionColumn + "|FTM_OldStringField; textFieldGrp -e -en 0 -text \"NewString\" " + $FTM_OptionColumn + "|FTM_NewStringField")
($FTM_OptionColumn + "|FTM_ReplaceStringChecker");

//帮助描述字段
string $FTM_HelpDescription = "\n 说 明:\n\n";
$FTM_HelpDescription += " 文件纹理管理器适用于Windows/Linux/MAC,以一种非常方便的方式管理文件纹理。\n\n";
$FTM_HelpDescription += " File Texture Manager 基本功能:\n\n";
$FTM_HelpDescription += " 1. 分析场景文件纹理\n";
$FTM_HelpDescription += " 2. 将原始纹理文件复制或移动到用户定义的路径\n";
$FTM_HelpDescription += " 3. 更新文件纹理的路径\n";
$FTM_HelpDescription += " 4. 也支持Mentalray纹理节点\n\n";
$FTM_HelpDescription += " FTM 额外功能:\n";
$FTM_HelpDescription += " 1. 替换文件纹理路径的根字符串。例如,重定向源代码\n";
$FTM_HelpDescription += " 2. 根据文件纹理的分辨率设置/取消设置内存效率。大于“阈值”(Threshold)(x或y)的纹理将设置为在设置模式下使用渲染器首选格式(Maya为BOT,mentalray为.map)。如果需要,将自动生成相应的内存高效文件。取消设置时,x和y中小于阈值的所有纹理都将设置为使用法线纹理,从该文件生成了内存高效纹理。BOT取消设置假设法线纹理存在于同一目录中。Mentalray.map unset将首先检查是否存在法线纹理。如果没有,FTM将尝试从.map文件中提取一个。指向序列的节点将被忽略。\n";
$FTM_HelpDescription += " 3. 将筛选类型设置为选定文件节点的指定类型。\n";
$FTM_HelpDescription += " 4. 将选定文件节点的纹理文件格式从“从”转换为“到”。如果“From”不是“*\”,则只处理纹理文件格式与“From \”匹配的文件节点。对于使用图像序列作为纹理文件的文件节点,需要指定转换范围,因此只打印出相应的命令,而不是真正执行任务。此函数使用Maya“imgcvt\”和mentalray\“imf_copy”多功能进行转换,因此请确保它们可以在系统可执行路径中找到。\n\n";
$FTM_HelpDescription += "【工作流程】:\n";
$FTM_HelpDescription += " 步骤 1. 分析场景文件纹理(可选择方式)\n";
$FTM_HelpDescription += " 步骤 2. 通过选中UI中的相关复选框,选择要管理的场景文件纹理(节点)\n 也可以通过自己的方法执行此操作,例如在Hypershade中选择它们。\n";
$FTM_HelpDescription += " 步骤 3. 根据需要设置选项。\n";
$FTM_HelpDescription += " 步骤 4. 通过按下相关按钮进行复制、移动或设置。\n\n";
$FTM_HelpDescription += "【小贴士】:\n";
$FTM_HelpDescription += " 1. 始终为每个纹理文件保留两个不同的版本。例如,“abc_LowRes.tga\”处于低分辨率,而“abc_HighRes.tga”处于高分辨率。使用低分辨率纹理来加速交互。只需记住在渲染之前使用FileTextureManager将每个文件纹理重置为指向相关的高分辨率纹理即可。(添加前缀、添加后缀,甚至替换字符串。)\n";
$FTM_HelpDescription += " 2. File Texture Manager 的UI不会像属性编辑器那样动态更新,因此最好重新-分析场景文件纹理 每次完成FTM工作时。如果您根本不使用分析功能,则无需执行此操作。\n\n";
$FTM_HelpDescription += "【注释】:\n";
$FTM_HelpDescription += " 1. 如果用户决定创建一个新文件夹,最终目标目录将等于目标目录加上新文件夹。\n";
$FTM_HelpDescription += " 2. 添加后缀功能对纹理文件名有限制。为了确保它按要求工作,文件名必须是常规格式,例如 filename.ext\”、“filename.[#…#].ext\“、\”filename.ext.[#…#]\n";
$FTM_HelpDescription += " 3. 添加prfix、添加后缀和替换字符串可以同时执行到每个文件纹理。替换字符串首先计算,然后添加后缀,最后添加前缀。\n";
$FTM_HelpDescription += " 4. 强烈建议不要在前缀、后缀、旧字符串和新字符串中包含“.\”。\n";
$FTM_HelpDescription += " 5. 有时过程会失败。原因可能多种多样。最可能的原因可能是以下两个原因之一或两者:a.在源目录中找不到纹理文件;b.被拒绝阅读、书写或删除。\n\n";
$FTM_HelpDescription += "【详情】:\n";
$FTM_HelpDescription += " 1. 分析场景文件纹理可以让你知道场景中有多少文件纹理,在哪里,它们是否存在,等等。它还允许用户只需单击一次就可以选择指向同一路径的所有纹理文件。\n";
$FTM_HelpDescription += " 2. 如何选择操作模式取决于不同的源目录状态。如果文件所在位置,请使用“自动”模式,否则请使用“手动”模式。\n";
$FTM_HelpDescription += " 3. 其他功能如UI中所示非常明确。\n";

scrollField -e -text $FTM_HelpDescription ($FTM_HelpForm + "|FTM_HelpField");
}


//判断输入字符串是格式扩展名、序列还是只是文件基名称的一部分

proc int FTM_FCWhatIs(string $string)
{
int $isWhat;
global string $FTM_FCAllFormats[];
$string = tolower($string);

if (stringArrayCount($string,$FTM_FCAllFormats))
$isWhat = 0;
else if (size(match("[0-9]*",$string)) == size($string))
$isWhat = 1;
else if ($string == "bot")
$isWhat = 3;
else
$isWhat = 2;

return $isWhat;
}

//判断纹理文件格式,仅根据可能的扩展名

proc string[] FTM_FCFileRegularName(string $file)
{
$file = substituteAll ("\\\\", $file, "/");
string $fileRegularName[] = stringToStringArray(basename($file,""),".");

string $fileName;
string $seqNum;
string $fileFormat;

switch (size($fileRegularName))
{
case 0:
break;
case 1:
$fileName = $fileRegularName[0];
break;
case 2:
if (FTM_FCWhatIs($fileRegularName[1]) == 0)
{
$fileName = $fileRegularName[0];
$fileFormat = $fileRegularName[1];
}
else if (FTM_FCWhatIs($fileRegularName[1]) == 1)
{
$fileName = $fileRegularName[0];
$seqNum = $fileRegularName[1];
}
else
$fileName = basename($file,"");
break;
default:
string $lastPiece = $fileRegularName[size($fileRegularName)-1];
if (FTM_FCWhatIs($lastPiece) == 0)
{
$fileFormat = $lastPiece;
$fileName = basenameEx($file);
$lastPiece = $fileRegularName[size($fileRegularName)-2];
if (FTM_FCWhatIs($lastPiece) == 1)
{
$seqNum = $lastPiece;
$fileName = basenameEx($fileName);
}
}
else if (FTM_FCWhatIs($lastPiece) == 1)
{
$seqNum = $lastPiece;
$fileName = basenameEx($file);
$lastPiece = $fileRegularName[size($fileRegularName)-2];
if (FTM_FCWhatIs($lastPiece) == 0)
{
$fileFormat = $lastPiece;
$fileName = basenameEx($fileName);
}
}
else if (FTM_FCWhatIs($lastPiece) == 3)
{
$fileFormat = $fileRegularName[size($fileRegularName)-2] + ".bot";
if (size($fileRegularName) == 3)
$fileName = $fileRegularName[0];
else
{
$lastPiece = $fileRegularName[size($fileRegularName)-3];
if (FTM_FCWhatIs($lastPiece) == 1)
{
$seqNum = $lastPiece;
$fileName = basenameEx(basenameEx(basenameEx($file)));
}
else
$fileName = basenameEx(basenameEx($file));
}
}
else // really sick!!!
$fileName = basename($file,"");
break;
}

$fileRegularName[0] = $fileName;
$fileRegularName[1] = $seqNum;
$fileRegularName[2] = $fileFormat;

return $fileRegularName;
}

proc string FTM_FCSubstituteLastPattern(string $inputString, string $targetPattern, string $newPattern)
{
$inputString = substituteAll("\\\\", $inputString, "/");


string $exp1 = "^.*" + $targetPattern + "+";
string $noTail = match($exp1,$inputString);


string $exp2 = $targetPattern + "+$";
string $newNoEnd = substitute($exp2,$noTail,$newPattern);

string $badChar[] = {"+",".","^","$","[","]","(",")"};
for ($char in $badChar)
$noTail = `substituteAllString $noTail $char ("\\"+$char)`;
string $exp3 = "^" + $noTail + "+";
string $outputString = substitute($exp3,$inputString,$newNoEnd);

$outputString = toNativePath($outputString);
return $outputString;
}


//分析输入文件名的位数

proc int FTM_FCDigitsNumber(string $fileName)
{
string $fileRegularName[] = FTM_FCFileRegularName($fileName);
$fileName = FTM_FCSubstituteLastPattern($fileName,$fileRegularName[1],"*");
string $filesInSeq[] = `getFileList -fs $fileName`;

int $digiNum = 0;
for ($i=0;$i<size($filesInSeq);$i++)
{
string $tmp[] = FTM_FCFileRegularName($filesInSeq[$i]);
if ($digiNum <= size($tmp[1]))
$digiNum = size($tmp[1]);
}

return $digiNum;
}

// 文件格式转换器

proc FTM_FCGo(int $progressUI, string $sourceFormatUI, string $targetFormat, int $handleSeq, int $updatePath, int $removeOrig)

{
if (FTM_SelCheck(`ls -sl -typ file `)) {
waitCursor -state on;
FTM_Log "start" "" "";

string $fileNodesList[] = FTM_FCGetMatches($sourceFormatUI);

int $isSeq[];
int $isOneOfSeq[];


string $file;
string $fileFC;
string $fileUpdatePath;
string $fileRemove;


if ($progressUI) {

int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size($fileNodesList)`;
}


for ($i=0;$i<size($fileNodesList);$i++){
FTM_Log "" ($fileNodesList[$i]+":") "";

if ($progressUI){

if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i+1;
$percentage = $progress * (100/size($fileNodesList));
progressWindow -e -pr $progress -st ("Handling " + $fileNodesList[$i] + " ...... " + $percentage + "%");
}

$file = toNativePath(substituteAll("\\\\",`getAttr ($fileNodesList[$i] + ".fileTextureName")`,"/"));
$fileFC = $file;
$fileRemove = $file;
string $fileRegularName[] = FTM_FCFileRegularName($file);
string $isBOT = `match "bot" $fileRegularName[2]`;
if (size($isBOT)) {
FTM_Log "" "Texture file is a BOT file. Skipped!" "";
continue;
}
string $targetFile = FTM_FCSubstituteLastPattern($file,$fileRegularName[2],$targetFormat);

if (!size($fileRegularName[2]))
$targetFile += "." + $targetFormat;
$fileUpdatePath = $targetFile;
string $cmp1,$cmp2;
$cmp1 = $fileUpdatePath;
$cmp2 = $fileRemove;
if (`about -nt`) {
$cmp1 = toNativePath(tolower($cmp1));
$cmp2 = toNativePath(tolower($cmp2));
}

if($cmp1 == $cmp2)
FTM_Log "" "" "This file node was already handled before. Process skipped.";

else{
$isSeq[$i] = 0;
$isOneOfSeq[$i] = 0;
if (`nodeType $fileNodesList[$i]` == "file" && size($fileRegularName[1])) {
if (`getAttr ($fileNodesList[$i] + ".useFrameExtension")`)
$isSeq[$i] = 1;
else
$isOneOfSeq[$i] = 1;
}


int $isMR_c = 0;
int $isMR_x = 0;
if ($fileRegularName[2] == "map" && $targetFormat != "map")
$isMR_x = 1;
else if ($fileRegularName[2] != "map" && $targetFormat == "map")
$isMR_c = 1;
string $cmdFC = "system(\"";
if ($isMR_c)
$cmdFC += "imf_copy -p -r";
else if ($isMR_x)
$cmdFC += "imf_copy";
else
$cmdFC += "imgcvt -t " + $targetFormat;
string $cmdUpdatePath = "setAttr -typ \"string\" " + $fileNodesList[$i] + ".fileTextureName ";
string $cmdRemoveOrig = "sysFile -del \"";

if (!$handleSeq && $isSeq[$i])
FTM_Log "" "" "Sequence was not selected to be handled. Skipped.";
else {
if ($handleSeq && $isSeq[$i]){
string $padding = "";
for ($j=0;$j<FTM_FCDigitsNumber($file);$j++)
$padding += "@";
$targetFile = FTM_FCSubstituteLastPattern($targetFile,$fileRegularName[1],$padding);
$fileFC = FTM_FCSubstituteLastPattern($file,$fileRegularName[1],$padding);
$fileRemove = FTM_FCSubstituteLastPattern($file,$fileRegularName[1],"*");

if (!$isMR_c && !$isMR_x)
$cmdFC += " -n startIn endIn stepIn -N startOut endOut stepOut";
}
$cmdFC += " \\\"" + encodeString($fileFC) + "\\\" \\\"" + encodeString($targetFile) + "\\\"";
if ($isMR_c || $isMR_x)
$cmdFC += " " + $targetFormat + "\")";
else
$cmdFC += "\")";

if (`file -q -ex $fileUpdatePath`)
FTM_Log "" "" "Convertion skipped. New format texture exists, maybe convertion has been done before.";
else{
if (!$isSeq[$i]){
string $cmdFCFeedback = eval($cmdFC);
if (size($cmdFCFeedback))
FTM_Log "" "" $cmdFCFeedback;
if (`file -q -ex $fileUpdatePath`)
FTM_Log "" "" ("Convertion succeeded. Converted from \"" + $fileFC + "\" to \"" + $targetFile + "\".");
else
FTM_Log "" "" "Convertion failed. Could be file permission problem, disk capacity problem or source texture is of unknown/unsupported format.";
}
else {
if (!$isMR_c && !$isMR_x)
FTM_Log "" "" ("Sequence specified. Command to execute (format conversion):" + $cmdFC);
else
FTM_Log "" "" "Sequence specified. Use \"imf_copy\" to convert your tetures. A simple loop might be needed.";
}
}

if ($updatePath) {
$cmdUpdatePath += "\"" + encodeString(toNativePath($fileUpdatePath)) + "\";";
$cmdRemoveOrig += encodeString($fileRemove) + "\";";

if (!$isSeq[$i]){
if (`file -q -ex $fileUpdatePath`){
if(catchQuiet(eval($cmdUpdatePath))) {
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
FTM_Log "" "" "WARNING: Path updating failed. So Original Texture Removing will not be done even if it was selected to.";
}
else {
FTM_Log "" "" ("Path updating succeeded. Set to \"" + (toNativePath($fileUpdatePath)) + "\".");

if ($removeOrig){
if ($isOneOfSeq[$i])
FTM_Log "" "" "Only one file of a whole sequence is used as texture, no file in the sequence is supposed to be removed.";
else if (!$isSeq[$i]){
if (!eval($cmdRemoveOrig))
FTM_Log "" "" "Original texture removing failed, could be file permission problem.";
else
FTM_Log "" "" ("Original texture removing succeeded. Removed \"" + $fileRemove + "\".");
}
}
}
}
else
FTM_Log "" "" "Convertion failed, Path Updating and Original Texture Removing will not be done even if they were selected to.";
}
else {
FTM_Log "" "" ("Sequence specified. Command to execute (update path info):" + $cmdUpdatePath);
if ($removeOrig)
FTM_Log "" "" ("Sequence specified. Command to execute (remove original textures):" + $cmdRemoveOrig);
}
}
}
}
}


if (!size($fileNodesList))
FTM_Log "" "No texture is of specified format." "";
if ($progressUI){
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
}
waitCursor -state off;
}
}

global proc string[] FTM_FCGetMatches (string $formatUI)
{
string $fileNodesList[];
string $tmpNodesList[] = `ls -sl -typ file `;
if (`FTM_SelCheck $tmpNodesList`) {
string $tmpNode;
string $tmpFile;

string $format = `optionMenu -q -v $formatUI`;
if ($format!="*") {
for ($tmpNode in $tmpNodesList) {
$tmpFile = `getAttr ($tmpNode + ".fileTextureName")`;
string $tmpFileRegularName[] = FTM_FCFileRegularName($tmpFile);
if (tolower($tmpFileRegularName[2]) == tolower($format))
$fileNodesList[size($fileNodesList)] = $tmpNode;
}
}
else
$fileNodesList = $tmpNodesList;
}
return $fileNodesList;
}

global proc FTM_FCGatherInfo(string $FTM_ExtraFunctionColumn)
{
string $sourceFormatUI = $FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCSourceMenu";
string $targetFormat = `optionMenu -q -v ($FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCTargetMenu")`;
int $handleSeq = `checkBox -q -v ($FTM_ExtraFunctionColumn + "|FTM_SeqCheck")`;
int $updatePath = `checkBox -q -v ($FTM_ExtraFunctionColumn + "|FTM_UpdateCheck")`;
int $removeOrig = `checkBox -q -v ($FTM_ExtraFunctionColumn + "|FTM_RemoveCheck")`;

FTM_FCGo 1
$sourceFormatUI
$targetFormat
$handleSeq
$updatePath
$removeOrig;
}


global proc FTM_FilterSetup(string $FTM_ExtraFunctionColumn)
{
string $Nodes[] = `ls -sl -typ file`;
if (`FTM_SelCheck $Nodes`) {
waitCursor -state on;
FTM_Log "start" "" "";
int $filterType = `optionMenu -q -sl ($FTM_ExtraFunctionColumn+"|FTM_FilterTypeRow|FTM_FilterTypeMenu")` -1;
string $filter = `optionMenu -q -v ($FTM_ExtraFunctionColumn+"|FTM_FilterTypeRow|FTM_FilterTypeMenu")`;

int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $Nodes`;

for ($i=0;$i<size($Nodes);$i++) {
FTM_Log "" ($Nodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($Nodes);
progressWindow -e -pr $progress -st ("Setting filter type, please wait...... " + $percentage + "%");

string $cmd = "setAttr " + $Nodes[$i] + ".filterType " + $filterType;
if (catchQuiet(eval($cmd)))
FTM_Log "" "" "Attribute \"filterType\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" ("Set filter type to \"" + $filter + "\"");
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}



global proc FTM_BOTSetup(int $FTM_BOTMode, string $FTM_ExtraFunctionColumn)
{
string $FTM_FileNodes[]=`ls -sl -typ file`;
if (`FTM_SelCheck $FTM_FileNodes`) {
waitCursor -state on;
FTM_Log "start" "" "";
int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $FTM_FileNodes`;

for ($i=0; $i<size($FTM_FileNodes); $i++){
FTM_Log "" ($FTM_FileNodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($FTM_FileNodes);
progressWindow -e -pr $progress -st ("Setting BOT options, please wait...... " + $percentage + "%");
if (`getAttr ($FTM_FileNodes[$i] + ".useFrameExtension")`) {
FTM_Log "" "" "Sequence specified, Skipped!";
continue;
}

int $resolution = `intFieldGrp -q -v1 ($FTM_ExtraFunctionColumn + "|FTM_BOTRow|FTM_BOTResFieldGrp")`;
float $xRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeX")`;
float $yRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeY")`;

if ($FTM_BOTMode) {
if ($xRes >= $resolution || $yRes >= $resolution) {
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
string $FTM_TheBOT = `substitute "(\\.bot)*$" $FTM_File ""` + ".bot";
string $BOTCmd = "makebot -c -r " + $resolution + " -i \"" + $FTM_File + "\" -o \"" + $FTM_TheBOT + "\"";
if (catchQuiet(eval($BOTCmd)))
FTM_Log "" "" "BOT file generation failed. Could be permission issue or the BOT file already exists.";
string $cacheCmd = "setAttr " + $FTM_FileNodes[$i] + ".useCache 1";
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_TheBOT + "\"";
if (catchQuiet(eval($cacheCmd)))
FTM_Log "" "" "WARNING: Attribute \"useCache\" is locked/connected and can NOT be modified!";
else if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "BOT setup OK.";
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is LOWER than specified threshold, skipped!");
}
else {
if ($xRes <= $resolution && $yRes <= $resolution) {
string $cacheCmd = "setAttr " + $FTM_FileNodes[$i] + ".useCache 0";
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
$FTM_File = `substitute "(\\.bot)*$" $FTM_File ""`;
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_File + "\"";
if (catchQuiet(eval($cacheCmd)))
FTM_Log "" "" "WARNING: Attribute \"useCache\" is locked/connected and can NOT be modified!";
else if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTexturename\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "BOT cancelled successfully.";
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is HIGHER than specified threshold, skipped!");
}
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}

global proc FTM_MAPSetup(int $FTM_MAPMode, string $FTM_ExtraFunctionColumn)
{
string $FTM_FileNodes[]=`ls -sl -typ file`;
if (`FTM_SelCheck $FTM_FileNodes`) {
waitCursor -state on;
FTM_Log "start" "" "";
int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $FTM_FileNodes`;

for ($i=0; $i<size($FTM_FileNodes); $i++){
FTM_Log "" ($FTM_FileNodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($FTM_FileNodes);
progressWindow -e -pr $progress -st ("Setting up mentalray memory-mapped textures, please wait...... " + $percentage + "%");

if (`getAttr ($FTM_FileNodes[$i] + ".useFrameExtension")`) {
FTM_Log "" "" "Sequence specified, Skipped!";
continue;
}

int $resolution = `intFieldGrp -q -v1 ($FTM_ExtraFunctionColumn + "|FTM_MAPRow|FTM_MAPResFieldGrp")`;
float $xRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeX")`;
float $yRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeY")`;

if ($FTM_MAPMode) {
if ($xRes >= $resolution || $yRes >= $resolution) {
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
string $FTM_TheMAP = `substitute "(\\.map)*$" $FTM_File ""` + ".map";
string $MAPCmd = "system(\"imf_copy -p -r \\\"" + (encodeString(`toNativePath $FTM_File`)) + "\\\" \\\"" + (encodeString(`toNativePath $FTM_TheMAP`)) + "\\\" map\")";
if (`file -q -ex $FTM_TheMAP`){
FTM_Log "" "" ("Mentalray memory-mapped texture file \"" + `toNativePath $FTM_TheMAP` + "\" already exists. FTM will directly use it.");
} else {
if (catchQuiet(eval($MAPCmd)))
FTM_Log "" "" "Mentalray memory-mapped texture file generation failed. Could be permission issue or 'imf_copy' can not be found in system executable path.";
}
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_TheMAP + "\"";
if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "Mentalray memory-mapped texture setup accomplished.";
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is LOWER than specified threshold, skipped!");
}
else {
if ($xRes <= $resolution && $yRes <= $resolution) {
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
string $FTM_TheMAP = $FTM_File;
$FTM_File = `substitute "(\\.map)*$" $FTM_File ""`;
int $wrong = 0;
if (!`file -q -ex $FTM_File`){
FTM_Log "" "" ("Normal texture file \"" + `toNativePath $FTM_File` + "\" doesn't exist.");
FTM_Log "" "" ("FTM is trying to extract one (in Maya iff format) from \"" + `toNativePath $FTM_TheMAP` + "\"");
string $UnMAPCmd = "system(\"imf_copy \\\"" + (encodeString(`toNativePath $FTM_TheMAP`)) + "\\\" \\\"" + (encodeString(`toNativePath $FTM_File`)) + "\\\" iff\")";
if (catchQuiet(eval($UnMAPCmd))) {
$wrong = 1;
FTM_Log "" "" ("WARNING: Extracting normal texture file from \"" + `toNativePath $FTM_TheMAP` + "\" failed.");
FTM_Log "" "" " Could be permission issue, or 'imf_copy' can not be found in system executable path, or original .map file is not a mentalray memory-mapped texture file.";
} else
FTM_Log "" "" ("Extraction succeed. => \"" + `toNativePath $FTM_File` + "\"");
}
if (!$wrong) {
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_File + "\"";
if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTexturename\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "Mentalray memory-mapped texture file unset accomplished.";
}
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is HIGHER than specified threshold, skipped!");
}
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}

global proc FTM_Substitute(string $oldRootField, string $newRootField)
{
string $oldRoot = `textFieldButtonGrp -q -text $oldRootField`;
$oldRoot = substituteAll("\\\\",$oldRoot,"/");
string $newRoot = `textFieldButtonGrp -q -text $newRootField`;
$newRoot = substituteAll("\\\\",$newRoot,"/");
if (size($oldRoot)==0 || size($newRoot)==0)
confirmDialog -t "File Texture Manager" -m "Both the Old Root filed and the New Root field must be filled!" -b "OK";
else {
string $fileNodes[] = `ls -sl -typ file -typ psdFileTex`;
if (`FTM_SelCheck $fileNodes`){
waitCursor -state 1;
FTM_Log "start" "" "";
string $badChar[] = {"+",".","^","$","[","]","(",")"};
for ($char in $badChar)
$oldRoot = `substituteAllString $oldRoot $char ("\\"+$char)`;

string $node;

int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $fileNodes`;

for ($i=0;$i<size($fileNodes);$i++) {
FTM_Log "" ($fileNodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($fileNodes);
progressWindow -e -pr $progress -st ("Redirecting, please wait...... " + $percentage + "%");

string $old = `getAttr ($fileNodes[$i]+".fileTextureName")`;
$old = `substituteAll "\\\\" $old "/"`;
string $new = `substitute $oldRoot $old $newRoot`;
string $cmd = "setAttr -typ \"string\" " + $fileNodes[$i] + ".fileTextureName \"" + $new + "\"";
if (catchQuiet(eval($cmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" ("Set to \"" + (toNativePath($new)) + "\"");
if (!`file -q -ex $new`)
FTM_Log "" "" ("WARNING: \"" + (toNativePath($new)) + "\" doesn't exist!");
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state 0;
}
}
}

global proc string getDirectoryFromTexCheck(string $checkLabel)
{
textFieldButtonGrp -e -text ($checkLabel+"/") FTM_TargetDirectoryField;
return $checkLabel;
}
global proc FTM_AnalyseFileTextures (string $FTM_ParentUI)
{
waitCursor -state on;

string $FTM_Groups[] = `FTM_FileTextureAnalyst`;

if (`columnLayout -q -ex ($FTM_ParentUI + "|FTM_AnalysisCheckerColumn")`)
deleteUI ($FTM_ParentUI + "|FTM_AnalysisCheckerColumn");

if (size($FTM_Groups) == 0)
text -e -l "找不到贴图文件" ($FTM_ParentUI + "|FTM_EmptyAnalysisText");
else
{
text -e -l "分析:" ($FTM_ParentUI + "|FTM_EmptyAnalysisText");

setParent $FTM_ParentUI;
columnLayout FTM_AnalysisCheckerColumn;
int $FTM_Groups_Size = size($FTM_Groups);
if ($FTM_Groups[0] == "FTM_EmptySocket_FTM")
$FTM_Groups_Size -= 1;
if ($FTM_Groups[1] == "FTM_MissingPathSocket_FTM")
$FTM_Groups_Size -= 1;
global string $lsCmd;
string $FTM_TotalResults = "总计 " + size(eval($lsCmd)) + " 文件纹理指向 " + $FTM_Groups_Size + "个路径 : ";
text -l $FTM_TotalResults;
text -l "" -h 10;

FTM_Log "start" "" "";
for ($FTM_Group in $FTM_Groups)
{
string $buffer[];
tokenize $FTM_Group "*" $buffer;
int $FTM_FilesStoredSize = size ($buffer)-1;
string $FTM_CurrentPath = $buffer[0];

string $FTM_FileTexturesAnalysis;
if ($FTM_CurrentPath=="FTM_EmptySocket_FTM" && $FTM_FilesStoredSize>0)
$FTM_FileTexturesAnalysis = $FTM_FilesStoredSize + " 未指定纹理。所以它们不存在。";
else if ($FTM_CurrentPath=="FTM_MissingPathSocket_FTM" && $FTM_FilesStoredSize>0)
$FTM_FileTexturesAnalysis = $FTM_FilesStoredSize + " 没有贴图路径信息 纹理不存在 ";
else
{
if ($FTM_FilesStoredSize>0){
$FTM_CurrentPath = `FTM_GetPath "路径" $FTM_CurrentPath`;
$FTM_FileTexturesAnalysis = $FTM_FilesStoredSize + " 个贴图路径指向: \"" + (toNativePath($FTM_CurrentPath)) + "\"";
}
}

string $FTM_CurrentFile[];
string $FTM_CurrentFiles = "";
string $FTM_Exist[] = {};
int $FTM_ExistSize = 0;
string $FTM_NotExist[] = {};
int $FTM_NotExistSize = 0;

for ($i=1; $i<size($buffer); $i++)
{

$FTM_CurrentFile[$i] = $buffer[$i];
$FTM_CurrentFiles = $FTM_CurrentFiles + $FTM_CurrentFile[$i] + " ";

string $FTM_CurrentFilePath = `getAttr ($FTM_CurrentFile[$i] + ".fileTextureName")`;
if ( `file -q -ex $FTM_CurrentFilePath`)
{
$FTM_Exist[$FTM_ExistSize] = $FTM_CurrentFile[$i];
$FTM_ExistSize = $FTM_ExistSize + 1;

}
else
{
$FTM_NotExist[$FTM_NotExistSize] = $FTM_CurrentFile[$i];
$FTM_NotExistSize = $FTM_NotExistSize + 1;
}
}

if (size($FTM_FileTexturesAnalysis)) {
string $FTM_MainChecker = `checkBox -l $FTM_FileTexturesAnalysis -al left`;
popupMenu -p $FTM_MainChecker;
string $cmd = "getDirectoryFromTexCheck(\""+$buffer[0]+"\")";

menuItem -label "复制" -c $cmd;
FTM_Log "" "" $FTM_FileTexturesAnalysis;

string $FTM_ExistSubChecker;
string $FTM_NotExistSubChecker;
if ($FTM_CurrentPath!="FTM_EmptySocket_FTM" && $FTM_CurrentPath!="FTM_MissingPathSocket_FTM")
{
columnLayout -adj 1 -cat left 30;

string $FTM_ExistFiles = "";
for ($i=0; $i<$FTM_ExistSize; $i++)
$FTM_ExistFiles = $FTM_ExistFiles + $FTM_Exist[$i] + " ";
$FTM_ExistSubChecker = `checkBox -l ($FTM_ExistSize + "个贴图已连接") -al left
-onc ("select -add " + $FTM_ExistFiles) -ofc ("if (" + $FTM_ExistSize + " > 0) select -deselect " + $FTM_ExistFiles)`;


string $FTM_NotExistFiles = "";
for ($i=0; $i<$FTM_NotExistSize; $i++)
$FTM_NotExistFiles = $FTM_NotExistFiles + $FTM_NotExist[$i] + " ";
$FTM_NotExistSubChecker = `checkBox -l ($FTM_NotExistSize + "个贴图未连接") -al left
-onc ("select -add " + $FTM_NotExistFiles) -ofc ("if (" + $FTM_NotExistSize + " > 0) select -deselect " + $FTM_NotExistFiles)`;
setParent ($FTM_ParentUI + "|FTM_AnalysisCheckerColumn");


checkBox -e -onc ("select -add " + $FTM_CurrentFiles + ";checkBox -e -v 1 -vis 0 " + $FTM_ExistSubChecker + ";checkBox -e -v 1 -vis 0 " + $FTM_NotExistSubChecker)
-ofc ("if (" + $FTM_FilesStoredSize + " > 0) select -deselect " + $FTM_CurrentFiles + ";checkBox -e -v 0 -vis 1 " + $FTM_ExistSubChecker + ";checkBox -e -v 0 -vis 1 " + $FTM_NotExistSubChecker)
$FTM_MainChecker;
}

else
checkBox -e -onc ("select -add " + $FTM_CurrentFiles) -ofc ("if (" + $FTM_FilesStoredSize + " > 0) select -deselect " + $FTM_CurrentFiles) $FTM_MainChecker;
}
}
FTM_Log "end" "" "";
}

waitCursor -state off;
}

global proc FTM_BrowseCmd (string $FTM_FileOrPath, string $FTM_TextField, string $FTM_WhichButton, int $FTM_BrowseType)
{
global string $FTM_WorkSpace;
if (size($FTM_WorkSpace) == 0)
{
$FTM_WorkSpace = `workspace -q -rd` + `workspace -q -fileRuleEntry "sourceImages"`;
$FTM_WorkSpace = `FTM_GetPath "path" $FTM_WorkSpace`;
}
workspace -dir $FTM_WorkSpace;

global int $FTM_NEW_MAYA;
if ($FTM_NEW_MAYA) {
if ($FTM_BrowseType == 0) $FTM_BrowseType = 1;
else if ($FTM_BrowseType == 4) $FTM_BrowseType = 3;
string $return[] = `fileDialog2 -ds 2 -cap $FTM_WhichButton -dir $FTM_WorkSpace -fm $FTM_BrowseType -okc $FTM_WhichButton -cc "Cancel"`;
string $path = $return[0];
if (!size($path)) $path = `textFieldButtonGrp -q -text $FTM_TextField`;
if ($FTM_FileOrPath == "file") $path += "bugQuickFix";
FTM_ChangeTextField $FTM_FileOrPath $FTM_TextField $path "";
}
else {
string $FTM_Temp = "";
$FTM_Temp += "FTM_ChangeTextField ";
$FTM_Temp += ("\"" + $FTM_FileOrPath + "\" ");
$FTM_Temp += ("\"" + $FTM_TextField + "\" ");
fileBrowser $FTM_Temp $FTM_WhichButton "" $FTM_BrowseType;
}
}

global proc FTM_ChangeTextField (string $FTM_FileOrPath, string $FTM_TextField, string $FTM_File, string $FTM_FileType)
{
string $FTM_Path = `FTM_GetPath $FTM_FileOrPath $FTM_File`;
textFieldButtonGrp -e -text (toNativePath($FTM_Path)) $FTM_TextField;
string $os = `about -os`;
if (gmatch($os, "*irix*") || gmatch($os, "*linux*"))
window -e -vis false projectViewerWindow;

global string $FTM_WorkSpace;
$FTM_WorkSpace = $FTM_Path;
}

global proc FTM_ResetUI (string $FTM_OptionColumn,string $FTM_AnalysisColumn,string $FTM_ExtraFunctionColumn,string $FTM_Tabs,string $FTM_CopyButton,string $FTM_MoveButton,string $FTM_SetButton)
{
waitCursor -state on;

global int $FTM_WIDTH, $FTM_HEIGHT;
window -e -wh $FTM_WIDTH $FTM_HEIGHT FTM_MainWindow;

text -e -l "未分析场景文件" ($FTM_AnalysisColumn + "|FTM_EmptyAnalysisText");

if (`columnLayout -q -ex ($FTM_AnalysisColumn + "|FTM_AnalysisCheckerColumn")`)
deleteUI ($FTM_AnalysisColumn + "|FTM_AnalysisCheckerColumn");
radioButtonGrp -e -select 1 ($FTM_OptionColumn + "|FTM_OperationMode");
textFieldButtonGrp -e -text "" -en 0 ($FTM_OptionColumn + "|FTM_SourceDirectoryField");
string $FTM_CurrentProject = `workspace -q -rd`;
string $FTM_CurrentSourceImagesDir = $FTM_CurrentProject + `workspace -q -fileRuleEntry "sourceImages"`;
string $FTM_SourceImages = `FTM_GetPath "path" $FTM_CurrentSourceImagesDir`;
textFieldButtonGrp -e -text $FTM_SourceImages ($FTM_OptionColumn + "|FTM_TargetDirectoryField");
checkBoxGrp -e -v1 0 ($FTM_OptionColumn + "|FTM_MakeFolderChecker");
textFieldGrp -e -text "MyTextureFiles" -en 0 ($FTM_OptionColumn + "|FTM_NewFolderNameField");
checkBox -e -v 0 ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_AddPrefixChecker");
textField -e -text "prefix_" -en 0 ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField");
checkBox -e -v 0 ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_AddSuffixChecker");
textField -e -text "_suffix" -en 0 ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField");
checkBoxGrp -e -v1 0 ($FTM_OptionColumn + "|FTM_ReplaceStringChecker");
textFieldGrp -e -text "OldString" -en 0 ($FTM_OptionColumn + "|FTM_OldStringField");
textFieldGrp -e -text "NewString" -en 0 ($FTM_OptionColumn + "|FTM_NewStringField");


textFieldButtonGrp -e -text "" ($FTM_ExtraFunctionColumn + "|oldRootField");
string $tmp = `workspace -q -rd` + `workspace -q -fileRuleEntry "sourceImages"`;
$tmp = `FTM_GetPath "path" $tmp`;
textFieldButtonGrp -e -text $tmp ($FTM_ExtraFunctionColumn + "|newRootField");
intFieldGrp -e -v1 1024 ($FTM_ExtraFunctionColumn + "|FTM_BOTRow|FTM_BOTResFieldGrp");
intFieldGrp -e -v1 1024 ($FTM_ExtraFunctionColumn + "|FTM_MAPRow|FTM_MAPResFieldGrp");
optionMenu -e -v "Mipmap" ($FTM_ExtraFunctionColumn + "|FTM_FilterTypeRow|FTM_FilterTypeMenu");
optionMenu -e -v "\*" ($FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCSourceMenu");
optionMenu -e -v "iff" ($FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCTargetMenu");
checkBox -e -v 0 ($FTM_ExtraFunctionColumn + "|FTM_SeqCheck");
checkBox -e -v 1 ($FTM_ExtraFunctionColumn + "|FTM_UpdateCheck");
checkBox -e -v 0 -en 1 ($FTM_ExtraFunctionColumn + "|FTM_RemoveCheck");


tabLayout -e -sti 1 $FTM_Tabs;

button -e -en 1 $FTM_CopyButton;
button -e -en 1 $FTM_MoveButton;
button -e -en 1 $FTM_SetButton;

global string $FTM_WorkSpace;
$FTM_WorkSpace = `workspace -q -rd` + `workspace -q -fileRuleEntry "sourceImages"`;
$FTM_WorkSpace = `FTM_GetPath "path" $FTM_WorkSpace`;

select -cl;
waitCursor -state off;
}

global proc FTM_Function (string $FTM_Function, string $FTM_OptionColumn)
{
global string $lsCmd;
string $FTM_SelectedFiles[] = eval($lsCmd + " -sl");
if (`FTM_SelCheck $FTM_SelectedFiles`)
{
waitCursor -state on;
FTM_Log "start" "" "";
int $wrong = 0;
int $FTM_OperationMode = `radioButtonGrp -q -select ($FTM_OptionColumn + "|FTM_OperationMode")`;


string $FTM_SourceDirectory;


string $FTM_TargetDirectory = `textFieldButtonGrp -q -text ($FTM_OptionColumn + "|FTM_TargetDirectoryField")`;
$FTM_TargetDirectory = `FTM_GetPath "path" $FTM_TargetDirectory`;

if ( `checkBoxGrp -q -v1 ($FTM_OptionColumn + "|FTM_MakeFolderChecker")` )
{
string $FTM_NewFolderName = `textFieldGrp -q -text ($FTM_OptionColumn + "|FTM_NewFolderNameField")`;
$FTM_TargetDirectory = $FTM_TargetDirectory + $FTM_NewFolderName;
if (!`file -q -ex $FTM_TargetDirectory`) {
if (`sysFile -md $FTM_TargetDirectory`)
FTM_Log "" ("Folder created: \"" + (toNativePath($FTM_TargetDirectory)) + "\".") "";
else {
$wrong = 1;
FTM_Log "" ("Folder can not be created: " + (toNativePath($FTM_TargetDirectory)) + "\".") "";
}
}
else {
if (!`filetest -w $FTM_TargetDirectory`) {
$wrong = 1;
FTM_Log "" ("Folder exists but is not writeable: " + (toNativePath($FTM_TargetDirectory)) + "\".") "";
}
}
$FTM_TargetDirectory = `FTM_GetPath "path" $FTM_TargetDirectory`;
}

if (!$wrong) {

string $FTM_FunctionCmd;
if ($FTM_Function == "Copy")
$FTM_FunctionCmd = "sysFile -cp ";
else if ($FTM_Function == "Move")
$FTM_FunctionCmd = "sysFile -mov ";


int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $FTM_SelectedFiles`;


for ($FTM_SelectedFile in $FTM_SelectedFiles)
{
FTM_Log "" ($FTM_SelectedFile+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$wrong = 0;

$progress += 1;
$percentage = $progress * (100/size($FTM_SelectedFiles));
progressWindow -e -pr $progress -st ("Handling " + $FTM_SelectedFile + " ...... " + $percentage + "%");


string $FTM_CurrentFile = `getAttr ($FTM_SelectedFile + ".fileTextureName")`;
string $FTM_SourceFile[] = `FTM_GetFile $FTM_CurrentFile`;
string $FTM_OriginSourceFile = $FTM_SourceFile[1];


if (size($FTM_OriginSourceFile) == 0)
FTM_Log "" "" "WARNING: File texture is not specified.";

else
{

if ( `checkBoxGrp -q -v1 ($FTM_OptionColumn + "|FTM_ReplaceStringChecker")` )
{
string $FTM_OldString = `textFieldGrp -q -tx ($FTM_OptionColumn + "|FTM_OldStringField")`;
string $badChar[] = {"+",".","^","$","[","]","(",")"};
for ($char in $badChar)
$FTM_OldString = `substituteAllString $FTM_OldString $char ("\\"+$char)`;
string $FTM_MatchExpression = "(" + $FTM_OldString + ")+";
string $FTM_NewString = `textFieldGrp -q -tx ($FTM_OptionColumn + "|FTM_NewStringField")`;
for ($i=0; $i<size($FTM_SourceFile[1]); $i++)
$FTM_SourceFile[1] = `substitute $FTM_MatchExpression $FTM_SourceFile[1] $FTM_NewString`;
}

string $FTM_Prefix;
string $FTM_Suffix;
string $FTM_SourceFileRegularName[] = `FTM_FCFileRegularName $FTM_SourceFile[1]`;

if ( `checkBox -q -v ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_AddPrefixChecker")` )
$FTM_Prefix = `textField -q -tx ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField")`;

if ( `checkBox -q -v ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_AddSuffixChecker")` )
$FTM_Suffix = `textField -q -tx ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField")`;


if (size($FTM_SourceFileRegularName[1]))
$FTM_SourceFileRegularName[1] = "." + $FTM_SourceFileRegularName[1];
if (size($FTM_SourceFileRegularName[2]))
$FTM_SourceFileRegularName[2] = "." + $FTM_SourceFileRegularName[2];
$FTM_SourceFile[1] = $FTM_Prefix + $FTM_SourceFileRegularName[0] + $FTM_Suffix + $FTM_SourceFileRegularName[1] + $FTM_SourceFileRegularName[2];


string $FTM_FinalCmd;
string $FTM_FunctionResult;
int $setWrong = 0;
if ($FTM_Function != "Set")
{
if ($FTM_OperationMode == 1)
{
$FTM_FinalCmd = $FTM_FunctionCmd + "\"" + `substituteAll "\\\\" ($FTM_TargetDirectory + $FTM_SourceFile[1]) "/"` + "\" \"" + `substituteAll "\\\\" $FTM_SourceFile[0] "/"` + "\"";
$FTM_FunctionResult = $FTM_Function + " \"" + `toNativePath $FTM_SourceFile[0]` + "\" to \"" + `toNativePath ($FTM_TargetDirectory + $FTM_SourceFile[1])` + "\". ";
}
else if ($FTM_OperationMode == 2)
{
$FTM_SourceDirectory = `textFieldButtonGrp -q -text ($FTM_OptionColumn + "|FTM_SourceDirectoryField")`;
$FTM_SourceDirectory = `FTM_GetPath "path" $FTM_SourceDirectory`;
$FTM_FinalCmd = $FTM_FunctionCmd + "\"" + `substituteAll "\\\\" ($FTM_TargetDirectory + $FTM_SourceFile[1]) "/"` + "\" \"" + `substituteAll "\\\\" ($FTM_SourceDirectory + $FTM_OriginSourceFile) "/"` + "\"";
$FTM_FunctionResult = $FTM_Function + " \"" + `toNativePath ($FTM_SourceDirectory + $FTM_OriginSourceFile)` + "\" to \"" + `toNativePath ($FTM_TargetDirectory + $FTM_SourceFile[1])` + "\". ";
}
}
else if ($FTM_Function == "Set")
{
string $path = `substituteAll "\\\\" ($FTM_TargetDirectory + $FTM_SourceFile[1]) "/"`;
string $cmd = "setAttr -typ \"string\" " + $FTM_SelectedFile + ".fileTextureName \"" + $path + "\"";
if (catchQuiet(eval($cmd))) {
$FTM_FunctionResult = "Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
$setWrong = 1;
}
else
$FTM_FunctionResult = "Set to \"" + `toNativePath ($FTM_TargetDirectory + $FTM_SourceFile[1])` + "\". ";
}


if ($FTM_Function != "Set") {
if (!eval($FTM_FinalCmd)) {
$wrong = 1;
FTM_Log "" "" ("WARNING: " + $FTM_Function + " can NOT be done, could be permission issue or path existence issue.");
}
}
if (!$wrong) {

if ( `file -q -ex ($FTM_TargetDirectory + $FTM_SourceFile[1])` )
{
if ($FTM_Function == "Move")
{
if ( `file -q -ex $FTM_SourceFile[0]` || `file -q -ex ($FTM_SourceDirectory + $FTM_OriginSourceFile)`)
{
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult + " But the original file is not removed. Check the HELP for possible reasons.";
FTM_Log "" "" ("WARNING: " + $FTM_FunctionResult);
}
else
{
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult;
FTM_Log "" "" $FTM_FunctionResult;
}
}
else
{
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult;
FTM_Log "" "" $FTM_FunctionResult;
}
}
else
{
if ($FTM_Function == "Set") {
if ($setWrong)
$FTM_FunctionResult = "WARNING: " + $FTM_FunctionResult;
else
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult + "But destination does NOT exist.";
}
else if ($FTM_Function != "Set")
$FTM_FunctionResult = "Fail: " + $FTM_FunctionResult + "Check Help tab for possible reasons.";
FTM_Log "" "" $FTM_FunctionResult;
}
}
}
}
}


progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}


//////构建主UI//////


global proc FileTextureManager ()
{

//版本检查
float $verCut = 2010;
global int $FTM_NEW_MAYA, $FTM_WIDTH, $FTM_HEIGHT;
$FTM_NEW_MAYA = 0;
$FTM_WIDTH = 380;
$FTM_HEIGHT = 600;

string $verString = `about -v`;
string $verString_tmp[];
tokenize $verString " " $verString_tmp;
float $verNum = $verString_tmp[0];
if ($verNum > $verCut) {
global int $FTM_NEW_MAYA, $FTM_WIDTH, $FTM_HEIGHT;
$FTM_NEW_MAYA = 1;
$FTM_WIDTH = 520; //宽度
$FTM_HEIGHT = 700; //高度
}
global string $FTM_FCAllFormats[];
$FTM_FCAllFormats = {"iff","sgi","tga","rgb","jpg","jpeg","map","tif","tiff","bmp","bw","icon","cin","pic","yuv","als","gif","lff","pxb","scn","ppm","pri","qtl","vst","rla"};

global string $lsCmd;
$lsCmd = "ls -typ file -typ psdFileTex ";

select -cl;

global string $FTM_MayaWorkSpace;
$FTM_MayaWorkSpace = `workspace -q -dir`;
global string $FTM_WorkSpace = "";

//确保窗口显示的大小正确
windowPref -enableAll false;
//如果UI退出,请将其删除
if (`window -exists FTM_MainWindow`)
deleteUI FTM_MainWindow;
//建立一个新的用户界面
global int $FTM_WIDTH, $FTM_HEIGHT;
window -title "File Texture Manager" -wh $FTM_WIDTH $FTM_HEIGHT -tlc 200 200 -ret FTM_MainWindow;
string $FTM_MainForm = `formLayout`;
string $FTM_Tabs = `tabLayout -imw 0 -imh 0`;
//选项选项卡
string $FTM_OptionForm = `formLayout`;
string $FTM_OptionScroll = `scrollLayout -cr true`;
string $FTM_OptionColumn = `columnLayout -adj 1 -rs 5`;
//分析区域
formLayout -nd 100 FTM_AnalyseForm;
string $FTM_AnalyseColumn = `columnLayout -cat both 30 -adj 1 -rs 5`;
button -l "分析场景文件纹理" -h 40 -w 250 FTM_AnalyseButton;
text -l "" -h 5;
text -l "选择要管理的文件(多选)";
string $FTM_AnalysisScroll = `scrollLayout -p FTM_AnalyseForm`;
string $FTM_AnalysisColumn = `columnLayout -cat left 15`;
text -l "未分析场景文件" FTM_EmptyAnalysisText;
button -e -c ("FTM_AnalyseFileTextures " + $FTM_AnalysisColumn) ($FTM_AnalyseColumn + "|FTM_AnalyseButton");
formLayout -e
-af $FTM_AnalyseColumn left 0
-af $FTM_AnalyseColumn right 0
-af $FTM_AnalyseColumn top 5
-af $FTM_AnalyseColumn bottom 200
-ac $FTM_AnalysisScroll top 5 $FTM_AnalyseColumn
-af $FTM_AnalysisScroll bottom 0
-af $FTM_AnalysisScroll left 0
-af $FTM_AnalysisScroll right 0
($FTM_OptionColumn + "|FTM_AnalyseForm");
setParent $FTM_OptionColumn;
separator -style "in" -h 10;
//操作模式
radioButtonGrp -l "工作模式 " -la2 "自动" "手动" -nrb 2 -select 1 -cl3 right left left -cw3 120 100 100 FTM_OperationMode;

separator -style "in" -h 5;

//设置源目录区域
textFieldButtonGrp -label "源目录" -text "" -buttonLabel "浏览" -adj 2 -en 0 -cw 1 120 -cw 3 60 -cl3 right left center FTM_SourceDirectoryField;

separator -style "in" -h 5;

//设置目标目录区域
string $FTM_CurrentProject = `workspace -q -rd`;
string $FTM_CurrentSourceImagesDir = $FTM_CurrentProject + `workspace -q -fileRuleEntry "sourceImages"`;
string $FTM_SourceImages = `FTM_GetPath "path" $FTM_CurrentSourceImagesDir`;
textFieldButtonGrp -label "目标目录: " -text $FTM_SourceImages -buttonLabel "浏览" -adj 2 -cw 1 120 -cw 3 60 -cl3 right left center FTM_TargetDirectoryField;
//创建新文件夹区域
checkBoxGrp -ncb 1 -l1 "在目标目录下创建新文件夹" -adj 1 -v1 0 -cat 1 left 101 FTM_MakeFolderChecker;
textFieldGrp -label "文件夹名称" -text "TextureFiles" -en 0 -cw2 120 180 -cl2 right left FTM_NewFolderNameField;
text -al center -l "FINAL目标目录将等于目标目录";
text -al center -l "加上新文件夹(如果用户决定创建新文件夹)";
separator -style "in" -h 5;
//更新纹理文件区域
rowLayout -nc 2 -cw 1 120 -cat 1 right 0 -cl2 left left FTM_AddPrefixRow;
checkBox -l "添加前缀" -v 0 FTM_AddPrefixChecker;
textField -tx "prefix_" -en 0 -w 150 FTM_PrefixField;
setParent $FTM_OptionColumn;
rowLayout -nc 2 -cw 1 120 -cat 1 right 0 -cl2 left left FTM_AddSuffixRow;
checkBox -l "添加后缀" -v 0 FTM_AddSuffixChecker;
textField -tx "_suffix" -en 0 -w 150 FTM_SuffixField;
setParent $FTM_OptionColumn;
checkBoxGrp -ncb 1 -l1 "替换字符串" -adj 1 -v1 0 -cat 1 left 101 FTM_ReplaceStringChecker;
textFieldGrp -l "旧名称:" -tx "Old String" -en 0 -cw2 120 150 -cl2 right left FTM_OldStringField;
textFieldGrp -l "新名称:" -tx "New String" -en 0 -cw2 120 150 -cl2 right left FTM_NewStringField;
formLayout -e
-af $FTM_OptionScroll top 5
-af $FTM_OptionScroll left 0
-af $FTM_OptionScroll right 0
-af $FTM_OptionScroll bottom 0
$FTM_OptionForm;
setParent $FTM_Tabs;
//附加功能选项卡
string $FTM_ExtraFunctionScroll = `scrollLayout -cr true`;
string $FTM_ExtraFunctionColumn = `columnLayout -cat both 15 -adj 1 -rs 5`;
//替换路径根区域
separator -style "none" -h 5;
text -fn "boldLabelFont" -al left -l "替换根路径";
textFieldButtonGrp -l "根路径" -text "" -buttonLabel "浏览" -adj 2 -en 1 -cw 1 80 -cw 3 60 -cl3 right left center oldRootField;
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"path\" " + $FTM_ExtraFunctionColumn + "|oldRootField \"Choose old root\" 4") ($FTM_ExtraFunctionColumn + "|oldRootField");
string $tmp = `workspace -q -rd` + `workspace -q -fileRuleEntry "sourceImages"`;
$tmp = `FTM_GetPath "path" $tmp`;
textFieldButtonGrp -l "新路径" -text $tmp -buttonLabel "浏览" -adj 2 -en 1 -cw 1 80 -cw 3 60 -cl3 right left center newRootField;
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"path\" " + $FTM_ExtraFunctionColumn + "|newRootField \"Choose new root\" 4") ($FTM_ExtraFunctionColumn + "|newRootField");
button -h 25 -l "替换" -c ("FTM_Substitute " + $FTM_ExtraFunctionColumn + "|oldRootField " + $FTM_ExtraFunctionColumn + "|newRootField");

separator -style "in" -h 10;
text -fn "boldLabelFont" -al left -l "内存效率 (仅限Maya“文件”节点)";
//text-fn“boldLabelFont”-al left-l“BOT设置(仅限Maya软件渲染器)”;
text -al left -l "\"BOT\" 设置(仅限Maya软件渲染器)";
rowLayout -nc 3 -adj 3
-cw 1 170 -cw 2 2 -cal 3 center
-cat 1 both 0 -cat 3 both 0
-rat 1 bottom 0 -rat 2 bottom 0 -rat 3 bottom 0
FTM_BOTRow;
intFieldGrp -nf 1 -adj 2 -cw 1 50 -cat 1 left 0 -cat 2 both 5 -l "阈值" -el "" -v1 1024 FTM_BOTResFieldGrp;
text -l "";
button -h 25 -l "设置 BOT" -c ("FTM_BOTSetup 1 " + $FTM_ExtraFunctionColumn);
setParent ..;
button -h 25 -l "取消设置 BOT" -c ("FTM_BOTSetup 0 " + $FTM_ExtraFunctionColumn);
text -al left -l "\".map\" 设置(仅限mental ray)";
rowLayout -nc 3 -adj 3
-cw 1 170 -cw 2 2 -cal 3 center
-cat 1 both 0 -cat 3 both 0
-rat 1 bottom 0 -rat 2 bottom 0 -rat 3 bottom 0
FTM_MAPRow;
intFieldGrp -nf 1 -adj 2 -cw 1 50 -cat 1 left 0 -cat 2 both 5 -l "阈值" -el "" -v1 1024 FTM_MAPResFieldGrp;
text -l "";
button -h 25 -l "设置 .map" -c ("FTM_MAPSetup 1 " + $FTM_ExtraFunctionColumn);
setParent ..;
button -h 25 -l "取消设置 .map" -c ("FTM_MAPSetup 0 " + $FTM_ExtraFunctionColumn);
// Filter setup area
separator -style "in" -h 10;
text -fn "boldLabelFont" -al left -l "过滤器设置(仅限Maya的“文件”/“sdFileTex”节点)";
rowLayout -nc 2 -cw 1 120 -cat 2 left 30 -adj 2 -cal 2 center -rat 1 bottom 0 FTM_FilterTypeRow;
optionMenu -l "过滤器类型" FTM_FilterTypeMenu;
menuItem -label "Off";
menuItem -label "Mipmap";
menuItem -label "Box";
menuItem -label "Quadratic";
menuItem -label "Quartic";
menuItem -label "Gaussian";
optionMenu -e -v "Mipmap" ($FTM_ExtraFunctionColumn + "|FTM_FilterTypeRow|FTM_FilterTypeMenu");
button -h 25 -l "设置过滤器类型 " -c ("FTM_FilterSetup " + $FTM_ExtraFunctionColumn);
setParent ..;
// Format conversion area
separator -style "in" -h 10;
text -fn "boldLabelFont" -al left -l "纹理文件格式转换";
rowLayout -nc 3 -cw 1 80 -cw 3 80 -cat 1 left 0 -cat 2 left 10 -cat 3 left 10 -adj 2 -cal 2 center FTM_FCRow;
optionMenu -l "源:" FTM_FCSourceMenu;
menuItem -label "\*";
global string $FTM_FCAllFormats[];
for ($i=0;$i<size($FTM_FCAllFormats);$i++)
menuItem -label $FTM_FCAllFormats[$i];
button -h 25 -l "选择匹配项" -c ("select -r `FTM_FCGetMatches \"" + $FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCSourceMenu\"`;");
optionMenu -l "转换" FTM_FCTargetMenu;
for ($i=0;$i<size($FTM_FCAllFormats);$i++)
menuItem -label $FTM_FCAllFormats[$i];
setParent ..;
checkBox -l "处理序列纹理。" -al "left" -v 0 FTM_SeqCheck;
checkBox -l "更新路径信息。" -al "left" -v 1 FTM_UpdateCheck;
checkBox -l "删除原始纹理。小心使用!" -al "left" -v 0 -en 1 FTM_RemoveCheck;
checkBox -e -onc ("checkBox -e -en 1 " + $FTM_ExtraFunctionColumn + "|FTM_RemoveCheck")
-ofc ("checkBox -e -en 0 " + $FTM_ExtraFunctionColumn + "|FTM_RemoveCheck")
($FTM_ExtraFunctionColumn + "|FTM_UpdateCheck");
button -l "转换" -h 25 -c ("FTM_FCGatherInfo " + $FTM_ExtraFunctionColumn);
setParent $FTM_Tabs;
//“帮助”选项卡
string $FTM_HelpForm = `formLayout`;
//描述区域
scrollField -ww true -editable false FTM_HelpField;
//关于文件纹理管理器
setParent $FTM_HelpForm;
global int $FTM_NEW_MAYA;
string $FTM_AboutFrame;
if ($FTM_NEW_MAYA) $FTM_AboutFrame = `frameLayout -l "关于 FileTextureManager" -fn boldLabelFont -cll 0 -bv true -li 5`;
else $FTM_AboutFrame = `frameLayout -l "关于 FileTextureManager" -la top -fn boldLabelFont -cll 0 -bv true -li 5`;
string $FTM_AboutForm = `formLayout`;
string $FTM_AboutTextLeft = `text -l "脚本名称 :\n更新时间 :\n作者 :\n汉化 :\n邮箱 :\n\n保留所有权" -al left`;
string $FTM_AboutTextRight = `text -l "FileTextureManager.mel\nMay, 2011\n叶(叶峰)\n三岁豆Er\nCrow.Yeh@gmail.com" -al left`;
formLayout -e
-af $FTM_AboutTextLeft left 10
-af $FTM_AboutTextLeft top 5
-an $FTM_AboutTextLeft right
-af $FTM_AboutTextLeft bottom 5
-ac $FTM_AboutTextRight left 10 $FTM_AboutTextLeft
-af $FTM_AboutTextRight top 5
-an $FTM_AboutTextRight right
-an $FTM_AboutTextRight bottom
$FTM_AboutForm;
formLayout -e
-ac FTM_HelpField bottom 5 $FTM_AboutFrame
-af FTM_HelpField top 5
-af FTM_HelpField left 0
-af FTM_HelpField right 0
-an $FTM_AboutFrame top
-af $FTM_AboutFrame left 0
-af $FTM_AboutFrame right 0
-af $FTM_AboutFrame bottom 0
$FTM_HelpForm;
//Function form.
setParent $FTM_MainForm;
string $FTM_FunctionForm = `formLayout -h 30 -numberOfDivisions 100`;
string $FTM_CopyButton = `button -l "复制"
-c ("FTM_Function \"Copy\" " + $FTM_OptionColumn)`;
string $FTM_MoveButton = `button -l "剪切"
-c ("FTM_Function \"Move\" " + $FTM_OptionColumn)`;
string $FTM_SetButton = `button -l "指定"
-c ("FTM_Function \"Set\" " + $FTM_OptionColumn)`;
string $FTM_ResetButton = `button -l "重置" -c ("FTM_ResetUI "+$FTM_OptionColumn+" "+$FTM_AnalysisColumn+" "+$FTM_ExtraFunctionColumn+" "+$FTM_Tabs+" "+$FTM_CopyButton+" "+$FTM_MoveButton+" "+$FTM_SetButton)`;
string $FTM_CloseButton = `button -l "退出"
-c ("deleteUI FTM_MainWindow; select -cl;global string $FTM_MayaWorkSpace; workspace -dir $FTM_MayaWorkSpace;")`;
formLayout -e
-ap $FTM_CopyButton right 1 20
-af $FTM_CopyButton top 0
-af $FTM_CopyButton left 0
-af $FTM_CopyButton bottom 0
-ap $FTM_MoveButton left 1 20
-ap $FTM_MoveButton right 1 40
-af $FTM_MoveButton top 0
-af $FTM_MoveButton bottom 0
-ap $FTM_SetButton left 1 40
-ap $FTM_SetButton right 1 60
-af $FTM_SetButton top 0
-af $FTM_SetButton bottom 0
-af $FTM_ResetButton top 0
-af $FTM_ResetButton bottom 0
-ap $FTM_ResetButton left 1 60
-ap $FTM_ResetButton right 1 80
-ap $FTM_CloseButton left 1 80
-af $FTM_CloseButton top 0
-af $FTM_CloseButton right 0
-af $FTM_CloseButton bottom 0
$FTM_FunctionForm;
formLayout -e
-af $FTM_Tabs top 0
-af $FTM_Tabs left 0
-af $FTM_Tabs right 0
-ac $FTM_Tabs bottom 3 $FTM_FunctionForm
-af $FTM_FunctionForm left 0
-af $FTM_FunctionForm right 0
-af $FTM_FunctionForm bottom 0
-an $FTM_FunctionForm top
$FTM_MainForm;

FTM_EditUIControl $FTM_OptionColumn $FTM_HelpForm;


string $tabCC = "button -e -en 0 " + $FTM_CopyButton + ";";
$tabCC += "button -e -en 0 " + $FTM_MoveButton + ";";
$tabCC += "button -e -en 0 " + $FTM_SetButton + ";";
$tabCC += "if (`tabLayout -q -sti " + $FTM_Tabs + "` == 1) {";
$tabCC += "button -e -en 1 " + $FTM_CopyButton + ";";
$tabCC += "button -e -en 1 " + $FTM_MoveButton + ";";
$tabCC += "button -e -en 1 " + $FTM_SetButton + ";";
$tabCC += "}";

tabLayout -e -tl $FTM_OptionForm "基本功能" -tl $FTM_ExtraFunctionScroll "附加功能" -tl $FTM_HelpForm "帮助" -psc $tabCC $FTM_Tabs;
showWindow FTM_MainWindow;
//确保其他窗口将以适当的大小显示
windowPref -enableAll true;
}

FileTextureManager;

//////////////////////////////////End//////////////////////////////////

源代码

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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////
///
/// Procedure Name : FileTextureManager
///
/// Version : 4.0.4
///
/// Updated : Aug 27, 2011
///
/// Author : Crow Yeh (YE Feng)
/// Contact : crow.yeh@gmail.com
///
/// History :
/// v4.0.4 Fixed problem of using it in Maya 2010.
/// v4.0.3 Support Maya version up to 2012.
/// v4.0.2 Tiny bugs fixed.
/// v4.0.1 Renamed a variable to avoid potential conflicts.
/// v4.0 Now compatible with Maya 2011
/// v3.4 Tiny bug fix
/// v3.3 Fixed a bug that dselects needed file nodes when user checks
/// checkBoxes not supposed to be checked.
/// v3.2 Fixed a bug that fails to recognise '\' as path separator
/// under OS other than Windows.
/// Extra functions now supports mentalray.
/// v3.1 Adds support (only basic functions) for Maya
/// psdFileTex node type and mentalray mentalRayTexture
/// node type.
///
/// Description :
///
/// File Texture Manager works on Windows/IRIX/Linux/MAC, manages file textures in a handy way.
/// FTM's basic functions:
/// 1. and give texture existence report.
/// 2. Copy or move the original texture files to user defined path (customizable).
/// 3. Update file textures' path info.
/// 4. Handle path strings. eg. replace string, add prefix, append suffix...
///
/// FTM's extra fuctions:
/// 1. Substitute file texture's path root string. eg. redirecting sourceiamges...
/// 2. Memory efficiency setup for textures. (BOT for Maya and .map for mentalray.)
/// 3. Filter type batch set.
/// 4. Texture file format conversion.
///
/// How to use :
///
/// Put the script in your scripts folder then start Maya. Type
/// and execute "FileTextureManager" in command line or Script
/// Editor, an UI window will appear. Then follow the help in the UI
/// window to finish your job. Have fun!
///
/// Inputs : None
///
/// Return : None
///
/// All Rights Reserved .
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////


///////////////////
// SCRIPT Starts //
///////////////////

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Procedure to check selection
//
proc int FTM_SelCheck(string $nodes[]){
int $sel = 0;
if (size($nodes))
$sel = 1;
else
confirmDialog -t "File Texture Manager" -m "At least one file texture node must be selected!" -b "OK";
return $sel;
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Procedure to remind user that job finished.
//
proc FTM_END(){
confirmDialog -t "File Texture Manager" -m "Job finished.\nRefer to Script Editor for details." -ma center -b "OK";
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Procedure to give logs
//
proc FTM_Log (string $type, string $node, string $log) {
string $finLog;
if (size($node))
$log = $node + "\n";
else
$log = "\t" + $log + "\n";
switch ($type) {
case "start":
$finLog = "\n***************************************************************************************************************\n\
File Texture Manager Log starts...\n\
***************************************************************************************************************\n";
break;
case "end":
$finLog = "***************************************************************************************************************\n\
File Texture Manager Log ends...\n\
***************************************************************************************************************\n";
break;
default:
$finLog = $log;
break;
}
print $finLog;
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Get the right format of path(folder) to match current OS.
//
proc string FTM_GetPath (string $FTM_FileOrPath, string $FTM_OldPath)
//$FTM_FileOrPath Input type: file or path
//$FTM_OldPath The input
{
//Do not use 'fromNativePath' here
//that only works on Windows!
$FTM_OldPath = `substituteAll "\\\\" $FTM_OldPath "/"`;
//Only want the path.
if ($FTM_FileOrPath == "file")
$FTM_OldPath = `dirname $FTM_OldPath`;
//Get rid of the slash at the end.
$FTM_OldPath = `substitute "/*$" $FTM_OldPath ""`;
//Get the right path.
string $FTM_RightPath;
if (size($FTM_OldPath)) $FTM_RightPath = `toNativePath ($FTM_OldPath + "/")`;
return $FTM_RightPath;
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Get the right format of input file's fullname (including path) to match current OS.
// Return a string array, the first element is the right format of the input file's
// fullname (including path), the second element is the shortname of input file (without path).
//
proc string[] FTM_GetFile (string $FTM_OldFullPath)
{
string $FTM_RightPath[];
string $FTM_PathElements[];
int $FTM_PathElementsSize;
// fullname
$FTM_OldFullPath = `substituteAll "\\\\" $FTM_OldFullPath "/"`;
$FTM_RightPath[0] = `toNativePath $FTM_OldFullPath`;
$FTM_PathElementsSize = `tokenize $FTM_OldFullPath "/" $FTM_PathElements`;
$FTM_RightPath[1] = $FTM_PathElements[$FTM_PathElementsSize - 1];
return $FTM_RightPath;
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Analyse all the file texture nodes in current scene.
//
proc string[] FTM_FileTextureAnalyst ()
{
// All the file texture nodes maybe point to texture files in different paths(folders).
// Here I use "group" to indicate different paths , which means there are n "groups" of
// different paths if the file texture nodes point to files in n different paths.

// The trick is to have an string array $FTM_Groups[], within which every element has corresponding
// path and nodes pointing to that path are concatenated togather with a "*", which is not supposed to appear in path or name.
// Every element has a form style of "path*node1*node2*node3..."
// Leave $FTM_Groups[0] for empty path, which means node's texture file was not specified.
// Leave $FTM_Groups[1] for files without path, which means only texture file's short name was presented but path info was missing.

// All the file texture nodes found in current scene.
global string $lsCmd;
string $FTM_Files[] = eval($lsCmd);

// Different groups.
string $FTM_Groups[];
int $FTM_GroupsSize;
if (size($FTM_Files)){
$FTM_Groups[0] = "FTM_EmptySocket_FTM";
$FTM_Groups[1] = "FTM_MissingPathSocket_FTM";
}

// Figure out how many "groups" there are in current scene, and put each file texture node
// into proper "group".
for ($eachFile in $FTM_Files)
{
$FTM_GroupsSize = size($FTM_Groups);
// Get the path of current file texture node
string $FTM_CurrentFullPath = substituteAll ("\\\\", `getAttr ($eachFile + ".fileTextureName")`, "/");
string $FTM_CurrentPath = dirname ($FTM_CurrentFullPath);

// File texutre was specified.
if (size($FTM_CurrentPath))
{
// Compare current path to all "groups" have been found. If matches then append current node
// to current "group" and exist the compare loop immediately.
// Remember that socket [0] is kept for nodes without texture file specified
// Remember that socket [1] is kept for nodes with texture file specified but with the path info missing
for ($j=2; $j<$FTM_GroupsSize; $j++)
{
string $buffer[];
tokenize $FTM_Groups[$j] "*" $buffer;
// Get the path of current "group".
string $FTM_OldPath = $buffer[0];
string $cmp1 = $FTM_CurrentPath;
string $cmp2 = $FTM_OldPath;
// Windows is not case sensitive to path
if (`about -nt`) {
$cmp1 = tolower($FTM_CurrentPath);
$cmp2 = tolower($FTM_OldPath);
}
// Compare current path to all "groups" have been found.
if ($cmp1 == $cmp2)
{
// Append current node to current group
string $tmp = $FTM_Groups[$j];
$tmp += "*" + $eachFile;
$FTM_Groups[$j] = $tmp;
break;
}
}
// No "group" matches means new "group" was found.
if ($j >= $FTM_GroupsSize)
{
// Create a new "group" and append current file texure node.
$FTM_Groups[$FTM_GroupsSize] = $FTM_CurrentPath + "*" + $eachFile;
continue;
}
}
// File texture was specified but the path info was missing
else if (size($FTM_CurrentFullPath)){
string $tmp = $FTM_Groups[1];
$tmp += "*" + $eachFile;
$FTM_Groups[1] = $tmp;
}
// File texture was not specified yet. Append current node to the first socket of groups
else{
string $tmp = $FTM_Groups[0];
$tmp += "*" + $eachFile;
$FTM_Groups[0] = $tmp;
}
}

select -cl;
return $FTM_Groups;
}

///////////////////////////////////////////////////////
///////////////////////////////////////////////////////
//
// Edit the UI Controls after they've been built
//
proc FTM_EditUIControl (string $FTM_OptionColumn, string $FTM_HelpForm)
{
// Operation mode
radioButtonGrp -e -on1 ("textFieldButtonGrp -e -en 0 -tx \"\" " + $FTM_OptionColumn + "|FTM_SourceDirectoryField")
-on2 ("textFieldButtonGrp -e -en 1 -tx \"\" " + $FTM_OptionColumn + "|FTM_SourceDirectoryField")
($FTM_OptionColumn + "|FTM_OperationMode");
// Set source directory
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"file\" \"" + $FTM_OptionColumn + "|FTM_SourceDirectoryField\" \"Set_S.D.\" 0")
($FTM_OptionColumn + "|FTM_SourceDirectoryField");
// Set target directory
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"path\" \"" + $FTM_OptionColumn + "|FTM_TargetDirectoryField\" \"Set_T.D.\" 4")
($FTM_OptionColumn + "|FTM_TargetDirectoryField");
// Make new folder
checkBoxGrp -e -on1 ("textFieldGrp -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_NewFolderNameField")
-of1 ("textFieldGrp -e -en 0 -text \"MyTextureFiles\" " + $FTM_OptionColumn + "|FTM_NewFolderNameField")
($FTM_OptionColumn + "|FTM_MakeFolderChecker");
// Add prefix
checkBox -e -onc ("textField -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField")
-ofc ("textField -e -en 0 -text \"prefix_\" " + $FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField")
($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_AddPrefixChecker");
// Add suffix
checkBox -e -onc ("textField -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField")
-ofc ("textField -e -en 0 -text \"_suffix\" " + $FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField")
($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_AddSuffixChecker");
// Replace string
checkBoxGrp -e -on1 ("textFieldGrp -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_OldStringField; textFieldGrp -e -en 1 -text \"\" " + $FTM_OptionColumn + "|FTM_NewStringField")
-of1 ("textFieldGrp -e -en 0 -text \"OldString\" " + $FTM_OptionColumn + "|FTM_OldStringField; textFieldGrp -e -en 0 -text \"NewString\" " + $FTM_OptionColumn + "|FTM_NewStringField")
($FTM_OptionColumn + "|FTM_ReplaceStringChecker");

// Help description field
string $FTM_HelpDescription = "\n[Description]:\n";
$FTM_HelpDescription += " File Texture Manager works on Windows/IRIX/Linux/MAC, manages file textures in a very handy way.\n";
$FTM_HelpDescription += " FTM basic functions:\n";
$FTM_HelpDescription += " 1. 分析场景文件纹理.\n";
$FTM_HelpDescription += " 2. Copy or move the original texture files to user defined path.\n";
$FTM_HelpDescription += " 3. Update file textures' path.\n";
$FTM_HelpDescription += " 4. Mentalray texture node is supported too.\n";
$FTM_HelpDescription += " FTM extra functions:\n";
$FTM_HelpDescription += " 1. Substitute file texture path's root string. eg. redirecting sourceiamges...\n";
$FTM_HelpDescription += " 2. Memory efficiency setup/unset for file textures according to their resolution. Textures larger than Threshold (in either x or y) will be set to use renderer prefered format (BOT for Maya and .map for mentalray) in setup mode. Corresponding memory-efficient file will be automatically generated if needed. When unset, all textures smaller than threshold in both x and y will be set to use normal textures, from which file the memory efficient texture was generated. BOT unset assume normal texture exist in the same directory. Mentalray .map unset will first check if the normal texture exist. If not, FTM will try to extract one from the .map file. Nodes pointing to sequences will be ignored.\n";
$FTM_HelpDescription += " 3. Set filter type to specified type for selected file nodes.\n";
$FTM_HelpDescription += " 4. Convert texture file format from \"From\" to \"To\" for selected file nodes. If \"From\" is not \"*\", only file nodes whose texture files format match \"From\" will be handled. For file nodes use image sequence as texture files, the range for conversion need to be specified, so only print out corresponding commands instead of really do the jobs. This function use Maya \"imgcvt\" and mentalray \"imf_copy\" ultility to do the conversion, so make sure them can be found in system executable path.\n\n";
$FTM_HelpDescription += "[Work Flow]:\n";
$FTM_HelpDescription += " Step 1. 分析场景文件纹理.(optional)\n";
$FTM_HelpDescription += " Step 2. Select scene file textures (nodes) you want to manage by checking on the related checkers in the UI. You can also do this by your own method, Eg. select them in Hypershade.\n";
$FTM_HelpDescription += " Step 3. Set options as needed.\n";
$FTM_HelpDescription += " Step 4. Do copy, move or set by pressing related button.\n\n";
$FTM_HelpDescription += "[Tips]:\n";
$FTM_HelpDescription += " 1. Always keep 2 different version for each texture file. Eg. \"abc_LowRes.tga\" is in low resolution while \"abc_HighRes.tga\" is in high resolution. Do your job using low-res textures to speed the interactant. Just remember to use FileTextureManager to reset each file texture to point to the related high-res texture before rendering. (Add prefix, add suffix or even replace string.)\n";
$FTM_HelpDescription += " 2. The FileTextureManager's UI does not update dynamically like what Attribute Editor does, so it is better to re-分析场景文件纹理 each time you finish an FTM job. This is not necessary if you do not use the Analyse function at all.\n\n";
$FTM_HelpDescription += "[Notes]:\n";
$FTM_HelpDescription += " 1. Final target directory will be equal to target directory plus new folder, if user decide to make a new folder.\n";
$FTM_HelpDescription += " 2. Add suffix function has limitation on the texture file name. To be sure it work as desired, the file name must be in a regular format, Eg. \"filename.ext\", \"filename.[#...#].ext\", \"filename.ext.[#...#]\", etc.\n";
$FTM_HelpDescription += " 3. Add prfix, add suffix and replace string can be executed at the same time to each file texture. Replace string is caculated first, then add suffix, and add prefix last.\n";
$FTM_HelpDescription += " 4. It is highly recommended not to contain \".\" in prefix, suffix, old string and new string.\n";
$FTM_HelpDescription += " 5. Sometimes process fails. The reason may be various. The most possible reason could be one of or both the following two: a. Texture file is not found in the source directory; b. Permission denied on reading or writing or deleting.\n\n";
$FTM_HelpDescription += "[Details]:\n";
$FTM_HelpDescription += " 1. Analysing scene file textures let you know how many file textures there are in the scene, where there are, whether they exist or not, etc. It also allows user select all the texture files point to same path by only one simple click.\n";
$FTM_HelpDescription += " 2. How to choose operation mode depends on different source directory status. If file is there where it point to, use Automatic mode, otherwise use Manual mode.\n";
$FTM_HelpDescription += " 3. Other functions are pretty definite as marked in the UI.\n";

scrollField -e -text $FTM_HelpDescription ($FTM_HelpForm + "|FTM_HelpField");
}

/////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
//
// judge if the input string is format extension, sequence or just part of file basename
//
proc int FTM_FCWhatIs(string $string)
{
int $isWhat;
// 0 - format extension
// 1 - sequence number
// 2 - nothing, is just file basename
// 3 - bot
global string $FTM_FCAllFormats[];
$string = tolower($string);

if (stringArrayCount($string,$FTM_FCAllFormats))
$isWhat = 0;
else if (size(match("[0-9]*",$string)) == size($string))
$isWhat = 1;
else if ($string == "bot")
$isWhat = 3;
else
$isWhat = 2;

return $isWhat;
}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
//
// judge texture file format, only according to the possible extension name
//
proc string[] FTM_FCFileRegularName(string $file)
{
$file = substituteAll ("\\\\", $file, "/");
string $fileRegularName[] = stringToStringArray(basename($file,""),".");
// try to make it like below
// [0] - file name
// [1] - the sequency number if presented, or ""
// [2] - the extension if presented, or ""

string $fileName;
string $seqNum;
string $fileFormat;

switch (size($fileRegularName))
{
case 0: // sick!!!
break;
case 1:// only file name presented
$fileName = $fileRegularName[0];
break;
case 2:// the second/last element could be sequence number, format extension or nothing;
if (FTM_FCWhatIs($fileRegularName[1]) == 0)
{
$fileName = $fileRegularName[0];
$fileFormat = $fileRegularName[1];
}
else if (FTM_FCWhatIs($fileRegularName[1]) == 1)
{
$fileName = $fileRegularName[0];
$seqNum = $fileRegularName[1];
}
else // FTM_FCWhatIs($fileRegularName[1]) = 2, which means the second/last element is just part of file basename, sick!!!
$fileName = basename($file,"");
break;
default: // there are 3 or more pieces. consider the last 2 only.
string $lastPiece = $fileRegularName[size($fileRegularName)-1];
if (FTM_FCWhatIs($lastPiece) == 0)
{
$fileFormat = $lastPiece;
$fileName = basenameEx($file);
// strip the last piece to judge again
$lastPiece = $fileRegularName[size($fileRegularName)-2];
if (FTM_FCWhatIs($lastPiece) == 1)
{
$seqNum = $lastPiece;
$fileName = basenameEx($fileName);
}
}
else if (FTM_FCWhatIs($lastPiece) == 1)
{
$seqNum = $lastPiece;
$fileName = basenameEx($file);
// strip the last piece to judge again
$lastPiece = $fileRegularName[size($fileRegularName)-2];
if (FTM_FCWhatIs($lastPiece) == 0)
{
$fileFormat = $lastPiece;
$fileName = basenameEx($fileName);
}
}
else if (FTM_FCWhatIs($lastPiece) == 3) //bot
{
$fileFormat = $fileRegularName[size($fileRegularName)-2] + ".bot";
if (size($fileRegularName) == 3)
$fileName = $fileRegularName[0];
else
{
$lastPiece = $fileRegularName[size($fileRegularName)-3];
if (FTM_FCWhatIs($lastPiece) == 1)
{
$seqNum = $lastPiece;
$fileName = basenameEx(basenameEx(basenameEx($file)));
}
else
$fileName = basenameEx(basenameEx($file));
}
}
else // really sick!!!
$fileName = basename($file,"");
break;
}

$fileRegularName[0] = $fileName;
$fileRegularName[1] = $seqNum;
$fileRegularName[2] = $fileFormat;

return $fileRegularName;
}

/////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////
//
// check string $inputString,replace the first (count backwards) matching string $targetPattern with string $newPattern
//
proc string FTM_FCSubstituteLastPattern(string $inputString, string $targetPattern, string $newPattern)
{
$inputString = substituteAll("\\\\", $inputString, "/");// avoid to handle "\" in the path

//strip everything behind the last string $targetPattern's existence
string $exp1 = "^.*" + $targetPattern + "+";
string $noTail = match($exp1,$inputString);

//replace the last $targetPattern in $noTail with $newPattern
string $exp2 = $targetPattern + "+$";
string $newNoEnd = substitute($exp2,$noTail,$newPattern);

//replace $noTail part in $inputString with $newNoEnd
// substitute all special characters
string $badChar[] = {"+",".","^","$","[","]","(",")"};
for ($char in $badChar)
$noTail = `substituteAllString $noTail $char ("\\"+$char)`;
string $exp3 = "^" + $noTail + "+";//take care of "\", so encode string.
string $outputString = substitute($exp3,$inputString,$newNoEnd);

$outputString = toNativePath($outputString);
return $outputString;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// to analyse the number of digits for input filename
//
proc int FTM_FCDigitsNumber(string $fileName)
{
string $fileRegularName[] = FTM_FCFileRegularName($fileName);
$fileName = FTM_FCSubstituteLastPattern($fileName,$fileRegularName[1],"*");
string $filesInSeq[] = `getFileList -fs $fileName`;

int $digiNum = 0;
for ($i=0;$i<size($filesInSeq);$i++)
{
string $tmp[] = FTM_FCFileRegularName($filesInSeq[$i]);
if ($digiNum <= size($tmp[1]))
$digiNum = size($tmp[1]);
}

return $digiNum;
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// the file format converter
//
proc FTM_FCGo(int $progressUI, string $sourceFormatUI, string $targetFormat, int $handleSeq, int $updatePath, int $removeOrig)
//int $progressUI - need progress UI; 0 - No UI for progress, which is designed for command line uses.
//string $sourceFormatUI - format convert from
//string $targetFormat - format convert to
//int $handleSeq - handle sequence textures; 0 - do not handle sequence textures.
//int $updatePath - update path info; 0 - do not update path info.
//int $removeOrig - remove original textures; 0 - do not remove original textures.
{
if (FTM_SelCheck(`ls -sl -typ file `)) {// if (0)
waitCursor -state on;
FTM_Log "start" "" "";
// list for file nodes to be handled
string $fileNodesList[] = FTM_FCGetMatches($sourceFormatUI);

int $isSeq[];// if it is using an image sequence as texture
int $isOneOfSeq[];// if it is using only one image of a whole sequence as texture.


string $file;// current file to be converted
string $fileFC;// current file in suitable naming for FC use
string $fileUpdatePath;// current file in suitable naming for updatePath use
string $fileRemove;// current file in proper naming for removing

// build progress feedback only in UI mode
if ($progressUI) {
// base of progress feedback setup
int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size($fileNodesList)`;
}

// executes cooresponding commands for each file node specified.
// the core process.
for ($i=0;$i<size($fileNodesList);$i++){ //for loop (1)
FTM_Log "" ($fileNodesList[$i]+":") "";
// build progress feedback only in UI mode
if ($progressUI){
// Check if the dialog has been cancelled
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i+1;
$percentage = $progress * (100/size($fileNodesList));
progressWindow -e -pr $progress -st ("Handling " + $fileNodesList[$i] + " ...... " + $percentage + "%");
}

$file = toNativePath(substituteAll("\\\\",`getAttr ($fileNodesList[$i] + ".fileTextureName")`,"/"));
$fileFC = $file;
$fileRemove = $file;
string $fileRegularName[] = FTM_FCFileRegularName($file);
string $isBOT = `match "bot" $fileRegularName[2]`;
if (size($isBOT)) {
FTM_Log "" "Texture file is a BOT file. Skipped!" "";
continue;
}
string $targetFile = FTM_FCSubstituteLastPattern($file,$fileRegularName[2],$targetFormat);

// it is bad that a file has no extension to indicate its format, so add one if needed.
if (!size($fileRegularName[2]))
$targetFile += "." + $targetFormat;
$fileUpdatePath = $targetFile;
string $cmp1,$cmp2;
$cmp1 = $fileUpdatePath;
$cmp2 = $fileRemove;
if (`about -nt`) {
$cmp1 = toNativePath(tolower($cmp1));
$cmp2 = toNativePath(tolower($cmp2));
}
// skip all process if the file node was already handled before.
if($cmp1 == $cmp2)
FTM_Log "" "" "This file node was already handled before. Process skipped.";

else{ //else (1)
$isSeq[$i] = 0;
$isOneOfSeq[$i] = 0;
if (`nodeType $fileNodesList[$i]` == "file" && size($fileRegularName[1])) {
if (`getAttr ($fileNodesList[$i] + ".useFrameExtension")`)
$isSeq[$i] = 1;
else
$isOneOfSeq[$i] = 1;
}

//commands to execute
int $isMR_c = 0; //create .map file
int $isMR_x = 0; //extract .map file
if ($fileRegularName[2] == "map" && $targetFormat != "map")
$isMR_x = 1;
else if ($fileRegularName[2] != "map" && $targetFormat == "map")
$isMR_c = 1;
string $cmdFC = "system(\"";
if ($isMR_c)
$cmdFC += "imf_copy -p -r";
else if ($isMR_x)
$cmdFC += "imf_copy";
else
$cmdFC += "imgcvt -t " + $targetFormat;
string $cmdUpdatePath = "setAttr -typ \"string\" " + $fileNodesList[$i] + ".fileTextureName ";
string $cmdRemoveOrig = "sysFile -del \"";

if (!$handleSeq && $isSeq[$i])
FTM_Log "" "" "Sequence was not selected to be handled. Skipped.";
else { //else (2)
// need to handle sequence textures
if ($handleSeq && $isSeq[$i]){
string $padding = "";
for ($j=0;$j<FTM_FCDigitsNumber($file);$j++)
$padding += "@";
$targetFile = FTM_FCSubstituteLastPattern($targetFile,$fileRegularName[1],$padding);
$fileFC = FTM_FCSubstituteLastPattern($file,$fileRegularName[1],$padding);
$fileRemove = FTM_FCSubstituteLastPattern($file,$fileRegularName[1],"*");

//command for sequence
if (!$isMR_c && !$isMR_x)
$cmdFC += " -n startIn endIn stepIn -N startOut endOut stepOut";
}
$cmdFC += " \\\"" + encodeString($fileFC) + "\\\" \\\"" + encodeString($targetFile) + "\\\"";
if ($isMR_c || $isMR_x)
$cmdFC += " " + $targetFormat + "\")";
else
$cmdFC += "\")";
// only do the convertion when target file doesn't exist,
// or convertion has been done before for other file node that shares the same texture.
if (`file -q -ex $fileUpdatePath`)
FTM_Log "" "" "Convertion skipped. New format texture exists, maybe convertion has been done before.";
else{ //else (3)
if (!$isSeq[$i]){
// system feedback
string $cmdFCFeedback = eval($cmdFC);
if (size($cmdFCFeedback))
FTM_Log "" "" $cmdFCFeedback;
if (`file -q -ex $fileUpdatePath`)
FTM_Log "" "" ("Convertion succeeded. Converted from \"" + $fileFC + "\" to \"" + $targetFile + "\".");
else
FTM_Log "" "" "Convertion failed. Could be file permission problem, disk capacity problem or source texture is of unknown/unsupported format.";
}
else { // for sequence, only print out command to execute.
if (!$isMR_c && !$isMR_x)
FTM_Log "" "" ("Sequence specified. Command to execute (format conversion):" + $cmdFC);
else
FTM_Log "" "" "Sequence specified. Use \"imf_copy\" to convert your tetures. A simple loop might be needed.";
}
}// else (3)

// need to update path info
if ($updatePath) {// if (1)
$cmdUpdatePath += "\"" + encodeString(toNativePath($fileUpdatePath)) + "\";";
$cmdRemoveOrig += encodeString($fileRemove) + "\";";

if (!$isSeq[$i]){// if (2)
if (`file -q -ex $fileUpdatePath`){ // if (3)
if(catchQuiet(eval($cmdUpdatePath))) {
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
FTM_Log "" "" "WARNING: Path updating failed. So Original Texture Removing will not be done even if it was selected to.";
}
else {// else (3)
FTM_Log "" "" ("Path updating succeeded. Set to \"" + (toNativePath($fileUpdatePath)) + "\".");
// need to remove old textures
// only remove old textures when updatePath is selected and updating succeeds
if ($removeOrig){ //if (4)
if ($isOneOfSeq[$i])
FTM_Log "" "" "Only one file of a whole sequence is used as texture, no file in the sequence is supposed to be removed.";
else if (!$isSeq[$i]){ // else if (1)
if (!eval($cmdRemoveOrig))
FTM_Log "" "" "Original texture removing failed, could be file permission problem.";
else
FTM_Log "" "" ("Original texture removing succeeded. Removed \"" + $fileRemove + "\".");
} // else if (1)
} // if (4)
}// else (3)
} // if (3)
else
FTM_Log "" "" "Convertion failed, Path Updating and Original Texture Removing will not be done even if they were selected to.";
} // if (2)
// for sequence, only print out command to execute
else { //else (4)
FTM_Log "" "" ("Sequence specified. Command to execute (update path info):" + $cmdUpdatePath);
if ($removeOrig)
FTM_Log "" "" ("Sequence specified. Command to execute (remove original textures):" + $cmdRemoveOrig);
}// else (4)
} // if (1)
} //else (2)
} // else(1)
} // for loop (1)

// feedback ends
if (!size($fileNodesList))
FTM_Log "" "No texture is of specified format." "";

// build progress feedback only in UI mode
if ($progressUI){
// finish progress feed back
progressWindow -ep;
FTM_Log "end" "" "";
// job done
FTM_END;
}
waitCursor -state off;
} // if (0)
}

////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////////
//
// analyse all possible file nodes to find out those match user's specification
//
global proc string[] FTM_FCGetMatches (string $formatUI)
{
string $fileNodesList[]; // list for file nodes to be handled
string $tmpNodesList[] = `ls -sl -typ file `; // list for all (selected) file nodes, which need to be analyse.
if (`FTM_SelCheck $tmpNodesList`) {
string $tmpNode; // each single file node in the list
string $tmpFile; // file that $tmpNode point to.

string $format = `optionMenu -q -v $formatUI`;
if ($format!="*") {// format from specified, so only handle files with that format
for ($tmpNode in $tmpNodesList) {
$tmpFile = `getAttr ($tmpNode + ".fileTextureName")`;
string $tmpFileRegularName[] = FTM_FCFileRegularName($tmpFile);
if (tolower($tmpFileRegularName[2]) == tolower($format))// extension matches, this file node need to be handled
$fileNodesList[size($fileNodesList)] = $tmpNode;
}
}
else // "*" was selected as format from, which means to handle all (selected) file nodes
$fileNodesList = $tmpNodesList;
}
return $fileNodesList;
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// info transfer, just to make sure FTM_FCGo can be run in command line.
//
global proc FTM_FCGatherInfo(string $FTM_ExtraFunctionColumn)
{
string $sourceFormatUI = $FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCSourceMenu";
string $targetFormat = `optionMenu -q -v ($FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCTargetMenu")`;
int $handleSeq = `checkBox -q -v ($FTM_ExtraFunctionColumn + "|FTM_SeqCheck")`;
int $updatePath = `checkBox -q -v ($FTM_ExtraFunctionColumn + "|FTM_UpdateCheck")`;
int $removeOrig = `checkBox -q -v ($FTM_ExtraFunctionColumn + "|FTM_RemoveCheck")`;

FTM_FCGo 1
$sourceFormatUI
$targetFormat
$handleSeq
$updatePath
$removeOrig;
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// Command for Filter Setup
//
global proc FTM_FilterSetup(string $FTM_ExtraFunctionColumn)
{
string $Nodes[] = `ls -sl -typ file`;
if (`FTM_SelCheck $Nodes`) {
waitCursor -state on;
FTM_Log "start" "" "";
int $filterType = `optionMenu -q -sl ($FTM_ExtraFunctionColumn+"|FTM_FilterTypeRow|FTM_FilterTypeMenu")` -1;
string $filter = `optionMenu -q -v ($FTM_ExtraFunctionColumn+"|FTM_FilterTypeRow|FTM_FilterTypeMenu")`;

int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $Nodes`;

for ($i=0;$i<size($Nodes);$i++) {
FTM_Log "" ($Nodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($Nodes);
progressWindow -e -pr $progress -st ("Setting filter type, please wait...... " + $percentage + "%");

string $cmd = "setAttr " + $Nodes[$i] + ".filterType " + $filterType;
if (catchQuiet(eval($cmd)))
FTM_Log "" "" "Attribute \"filterType\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" ("Set filter type to \"" + $filter + "\"");
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// Command for BOT setup
//
global proc FTM_BOTSetup(int $FTM_BOTMode, string $FTM_ExtraFunctionColumn)
//$FTM_BOTMode - 1 Setup
// - 0 Unset
{
string $FTM_FileNodes[]=`ls -sl -typ file`;
if (`FTM_SelCheck $FTM_FileNodes`) {
waitCursor -state on;
FTM_Log "start" "" "";
int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $FTM_FileNodes`;

for ($i=0; $i<size($FTM_FileNodes); $i++){
FTM_Log "" ($FTM_FileNodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($FTM_FileNodes);
progressWindow -e -pr $progress -st ("Setting BOT options, please wait...... " + $percentage + "%");

// Do not handle sequence textures
if (`getAttr ($FTM_FileNodes[$i] + ".useFrameExtension")`) {
FTM_Log "" "" "Sequence specified, Skipped!";
continue;
}

int $resolution = `intFieldGrp -q -v1 ($FTM_ExtraFunctionColumn + "|FTM_BOTRow|FTM_BOTResFieldGrp")`;
float $xRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeX")`;
float $yRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeY")`;

if ($FTM_BOTMode) {// Setup
if ($xRes >= $resolution || $yRes >= $resolution) {
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
string $FTM_TheBOT = `substitute "(\\.bot)*$" $FTM_File ""` + ".bot";
string $BOTCmd = "makebot -c -r " + $resolution + " -i \"" + $FTM_File + "\" -o \"" + $FTM_TheBOT + "\"";
if (catchQuiet(eval($BOTCmd)))
FTM_Log "" "" "BOT file generation failed. Could be permission issue or the BOT file already exists.";
string $cacheCmd = "setAttr " + $FTM_FileNodes[$i] + ".useCache 1";
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_TheBOT + "\"";
if (catchQuiet(eval($cacheCmd)))
FTM_Log "" "" "WARNING: Attribute \"useCache\" is locked/connected and can NOT be modified!";
else if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "BOT setup OK.";
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is LOWER than specified threshold, skipped!");
}
else {// Cancel
if ($xRes <= $resolution && $yRes <= $resolution) {
string $cacheCmd = "setAttr " + $FTM_FileNodes[$i] + ".useCache 0";
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
$FTM_File = `substitute "(\\.bot)*$" $FTM_File ""`;
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_File + "\"";
if (catchQuiet(eval($cacheCmd)))
FTM_Log "" "" "WARNING: Attribute \"useCache\" is locked/connected and can NOT be modified!";
else if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTexturename\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "BOT cancelled successfully.";
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is HIGHER than specified threshold, skipped!");
}
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// Command for mentalray memory-mapped texture (.map) setup
//
global proc FTM_MAPSetup(int $FTM_MAPMode, string $FTM_ExtraFunctionColumn)
//$FTM_MAPMode - 1 Setup
// - 0 Unset
{
string $FTM_FileNodes[]=`ls -sl -typ file`;
if (`FTM_SelCheck $FTM_FileNodes`) {
waitCursor -state on;
FTM_Log "start" "" "";
int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $FTM_FileNodes`;

for ($i=0; $i<size($FTM_FileNodes); $i++){
FTM_Log "" ($FTM_FileNodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($FTM_FileNodes);
progressWindow -e -pr $progress -st ("Setting up mentalray memory-mapped textures, please wait...... " + $percentage + "%");

// Do not handle sequence textures
if (`getAttr ($FTM_FileNodes[$i] + ".useFrameExtension")`) {
FTM_Log "" "" "Sequence specified, Skipped!";
continue;
}

int $resolution = `intFieldGrp -q -v1 ($FTM_ExtraFunctionColumn + "|FTM_MAPRow|FTM_MAPResFieldGrp")`;
float $xRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeX")`;
float $yRes = `getAttr ($FTM_FileNodes[$i] + ".outSizeY")`;

if ($FTM_MAPMode) {// Setup
if ($xRes >= $resolution || $yRes >= $resolution) {
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
string $FTM_TheMAP = `substitute "(\\.map)*$" $FTM_File ""` + ".map";
string $MAPCmd = "system(\"imf_copy -p -r \\\"" + (encodeString(`toNativePath $FTM_File`)) + "\\\" \\\"" + (encodeString(`toNativePath $FTM_TheMAP`)) + "\\\" map\")";
if (`file -q -ex $FTM_TheMAP`){ // .map is already there.
FTM_Log "" "" ("Mentalray memory-mapped texture file \"" + `toNativePath $FTM_TheMAP` + "\" already exists. FTM will directly use it.");
} else {
if (catchQuiet(eval($MAPCmd)))
FTM_Log "" "" "Mentalray memory-mapped texture file generation failed. Could be permission issue or 'imf_copy' can not be found in system executable path.";
}
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_TheMAP + "\"";
if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "Mentalray memory-mapped texture setup accomplished.";
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is LOWER than specified threshold, skipped!");
}
else {// Unset
if ($xRes <= $resolution && $yRes <= $resolution) {
string $FTM_File = `getAttr ($FTM_FileNodes[$i] + ".fileTextureName")`;
$FTM_File = `substituteAll "\\\\" $FTM_File "/"`;
string $FTM_TheMAP = $FTM_File;
$FTM_File = `substitute "(\\.map)*$" $FTM_File ""`;
int $wrong = 0;
if (!`file -q -ex $FTM_File`){
FTM_Log "" "" ("Normal texture file \"" + `toNativePath $FTM_File` + "\" doesn't exist.");
FTM_Log "" "" ("FTM is trying to extract one (in Maya iff format) from \"" + `toNativePath $FTM_TheMAP` + "\"");
string $UnMAPCmd = "system(\"imf_copy \\\"" + (encodeString(`toNativePath $FTM_TheMAP`)) + "\\\" \\\"" + (encodeString(`toNativePath $FTM_File`)) + "\\\" iff\")";
if (catchQuiet(eval($UnMAPCmd))) {
$wrong = 1;
FTM_Log "" "" ("WARNING: Extracting normal texture file from \"" + `toNativePath $FTM_TheMAP` + "\" failed.");
FTM_Log "" "" " Could be permission issue, or 'imf_copy' can not be found in system executable path, or original .map file is not a mentalray memory-mapped texture file.";
} else
FTM_Log "" "" ("Extraction succeed. => \"" + `toNativePath $FTM_File` + "\"");
}
if (!$wrong) {
string $pathCmd = "setAttr -typ \"string\" " + $FTM_FileNodes[$i] + ".fileTextureName \"" + $FTM_File + "\"";
if (catchQuiet(eval($pathCmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTexturename\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" "Mentalray memory-mapped texture file unset accomplished.";
}
}
else
FTM_Log "" "" ("Resolution \"" + $xRes + "x" + $yRes + "\" is HIGHER than specified threshold, skipped!");
}
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// Command to substitute path root
//
global proc FTM_Substitute(string $oldRootField, string $newRootField)
{
string $oldRoot = `textFieldButtonGrp -q -text $oldRootField`;
$oldRoot = substituteAll("\\\\",$oldRoot,"/");
string $newRoot = `textFieldButtonGrp -q -text $newRootField`;
$newRoot = substituteAll("\\\\",$newRoot,"/");
if (size($oldRoot)==0 || size($newRoot)==0)
confirmDialog -t "File Texture Manager" -m "Both the Old Root filed and the New Root field must be filled!" -b "OK";
else {
string $fileNodes[] = `ls -sl -typ file -typ psdFileTex`;
if (`FTM_SelCheck $fileNodes`){
waitCursor -state 1;
FTM_Log "start" "" "";
// substitute all special characters
string $badChar[] = {"+",".","^","$","[","]","(",")"};
for ($char in $badChar)
$oldRoot = `substituteAllString $oldRoot $char ("\\"+$char)`;

string $node;

int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $fileNodes`;

for ($i=0;$i<size($fileNodes);$i++) {
FTM_Log "" ($fileNodes[$i]+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$progress = $i;
$percentage = $progress * 100 / size($fileNodes);
progressWindow -e -pr $progress -st ("Redirecting, please wait...... " + $percentage + "%");

string $old = `getAttr ($fileNodes[$i]+".fileTextureName")`;
$old = `substituteAll "\\\\" $old "/"`;
string $new = `substitute $oldRoot $old $newRoot`;
string $cmd = "setAttr -typ \"string\" " + $fileNodes[$i] + ".fileTextureName \"" + $new + "\"";
if (catchQuiet(eval($cmd)))
FTM_Log "" "" "WARNING: Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
else
FTM_Log "" "" ("Set to \"" + (toNativePath($new)) + "\"");
if (!`file -q -ex $new`)
FTM_Log "" "" ("WARNING: \"" + (toNativePath($new)) + "\" doesn't exist!");
}
progressWindow -ep;
FTM_Log "end" "" "";
FTM_END;
waitCursor -state 0;
}
}
}

global proc string getDirectoryFromTexCheck(string $checkLabel)
{
textFieldButtonGrp -e -text ($checkLabel+"/") FTM_TargetDirectoryField;
return $checkLabel;
}
//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
// Command executed when "分析场景文件纹理" button pressed.
//
global proc FTM_AnalyseFileTextures (string $FTM_ParentUI)
{
waitCursor -state on;

string $FTM_Groups[] = `FTM_FileTextureAnalyst`;

// Make sure the corresponding UI uniqe.
if (`columnLayout -q -ex ($FTM_ParentUI + "|FTM_AnalysisCheckerColumn")`)
deleteUI ($FTM_ParentUI + "|FTM_AnalysisCheckerColumn");

if (size($FTM_Groups) == 0)
text -e -l "No file textures found!" ($FTM_ParentUI + "|FTM_EmptyAnalysisText");
else
{
text -e -l "Analysis:" ($FTM_ParentUI + "|FTM_EmptyAnalysisText");

setParent $FTM_ParentUI;
columnLayout FTM_AnalysisCheckerColumn;
int $FTM_Groups_Size = size($FTM_Groups);
if ($FTM_Groups[0] == "FTM_EmptySocket_FTM")
$FTM_Groups_Size -= 1;
if ($FTM_Groups[1] == "FTM_MissingPathSocket_FTM")
$FTM_Groups_Size -= 1;
global string $lsCmd;
string $FTM_TotalResults = "Total " + size(eval($lsCmd)) + " file textures point to " + $FTM_Groups_Size + " (different) path(s) : ";
text -l $FTM_TotalResults;
text -l "" -h 10;

FTM_Log "start" "" "";
// Analyse each file in each "group".
for ($FTM_Group in $FTM_Groups)
{
string $buffer[];
tokenize $FTM_Group "*" $buffer;
int $FTM_FilesStoredSize = size ($buffer)-1;
string $FTM_CurrentPath = $buffer[0];

string $FTM_FileTexturesAnalysis;
// File texture not specified yet. In other words, empty file texture nodes.
if ($FTM_CurrentPath=="FTM_EmptySocket_FTM" && $FTM_FilesStoredSize>0)
$FTM_FileTexturesAnalysis = $FTM_FilesStoredSize + " texture(s) NOT specified. So they are NOT exist(s).";
// File texture specified, but no path information.
else if ($FTM_CurrentPath=="FTM_MissingPathSocket_FTM" && $FTM_FilesStoredSize>0)
$FTM_FileTexturesAnalysis = $FTM_FilesStoredSize + " texture(s) have no path information. So they are NOT exist(s).";
// Normal status.
else
{
if ($FTM_FilesStoredSize>0){
// Correct the path format for current OS.
$FTM_CurrentPath = `FTM_GetPath "path" $FTM_CurrentPath`;
$FTM_FileTexturesAnalysis = $FTM_FilesStoredSize + " texture(s) point to \"" + (toNativePath($FTM_CurrentPath)) + "\"";
}
}

// Queue the names of the files stored in current "group" for later quick selecting.
string $FTM_CurrentFile[];
string $FTM_CurrentFiles = "";
// Strings used to hold files exist or notExist.
string $FTM_Exist[] = {};
int $FTM_ExistSize = 0;
string $FTM_NotExist[] = {};
int $FTM_NotExistSize = 0;

for ($i=1; $i<size($buffer); $i++)
{
// Store the names of files in current "group".
$FTM_CurrentFile[$i] = $buffer[$i];
$FTM_CurrentFiles = $FTM_CurrentFiles + $FTM_CurrentFile[$i] + " ";

// Check if the file exsist or not, then asign the name to responding variable.
string $FTM_CurrentFilePath = `getAttr ($FTM_CurrentFile[$i] + ".fileTextureName")`;
if ( `file -q -ex $FTM_CurrentFilePath`)
{
$FTM_Exist[$FTM_ExistSize] = $FTM_CurrentFile[$i];
$FTM_ExistSize = $FTM_ExistSize + 1;

}
else
{
$FTM_NotExist[$FTM_NotExistSize] = $FTM_CurrentFile[$i];
$FTM_NotExistSize = $FTM_NotExistSize + 1;
}
}

if (size($FTM_FileTexturesAnalysis)) {
string $FTM_MainChecker = `checkBox -l $FTM_FileTexturesAnalysis -al left`;
popupMenu -p $FTM_MainChecker;
string $cmd = "getDirectoryFromTexCheck(\""+$buffer[0]+"\")";

menuItem -label "copy" -c $cmd;
FTM_Log "" "" $FTM_FileTexturesAnalysis;

// Only build responding sub-checker for the files have path information.
string $FTM_ExistSubChecker;
string $FTM_NotExistSubChecker;
if ($FTM_CurrentPath!="FTM_EmptySocket_FTM" && $FTM_CurrentPath!="FTM_MissingPathSocket_FTM")
{
columnLayout -adj 1 -cat left 30;
// A list of exist files, which is used for selection.
string $FTM_ExistFiles = "";
for ($i=0; $i<$FTM_ExistSize; $i++)
$FTM_ExistFiles = $FTM_ExistFiles + $FTM_Exist[$i] + " ";
$FTM_ExistSubChecker = `checkBox -l ($FTM_ExistSize + " of them exist(s).") -al left
-onc ("select -add " + $FTM_ExistFiles) -ofc ("if (" + $FTM_ExistSize + " > 0) select -deselect " + $FTM_ExistFiles)`;

// A list of NOT exist files, which is used for selection.
string $FTM_NotExistFiles = "";
for ($i=0; $i<$FTM_NotExistSize; $i++)
$FTM_NotExistFiles = $FTM_NotExistFiles + $FTM_NotExist[$i] + " ";
$FTM_NotExistSubChecker = `checkBox -l ($FTM_NotExistSize + " of them NOT exist(s).") -al left
-onc ("select -add " + $FTM_NotExistFiles) -ofc ("if (" + $FTM_NotExistSize + " > 0) select -deselect " + $FTM_NotExistFiles)`;
setParent ($FTM_ParentUI + "|FTM_AnalysisCheckerColumn");

// Main checker's onCommand and offCommand should influnce responding subcheckers in this case;
checkBox -e -onc ("select -add " + $FTM_CurrentFiles + ";checkBox -e -v 1 -vis 0 " + $FTM_ExistSubChecker + ";checkBox -e -v 1 -vis 0 " + $FTM_NotExistSubChecker)
-ofc ("if (" + $FTM_FilesStoredSize + " > 0) select -deselect " + $FTM_CurrentFiles + ";checkBox -e -v 0 -vis 1 " + $FTM_ExistSubChecker + ";checkBox -e -v 0 -vis 1 " + $FTM_NotExistSubChecker)
$FTM_MainChecker;
}
// Main checker's onCommand and offCommand should NOT influnce responding subcheckers in this case;
else
checkBox -e -onc ("select -add " + $FTM_CurrentFiles) -ofc ("if (" + $FTM_FilesStoredSize + " > 0) select -deselect " + $FTM_CurrentFiles) $FTM_MainChecker;
}
}
FTM_Log "end" "" "";
}

waitCursor -state off;
}

//////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////
//
//Comand executed when Browse button pressed.
//
global proc FTM_BrowseCmd (string $FTM_FileOrPath, string $FTM_TextField, string $FTM_WhichButton, int $FTM_BrowseType)
//$FTM_FileOrPath Pass to FTM_ChangeTextField
//$FTM_TextField Pass to FTM_ChangeTextField
//$FTM_WhichButton Pass to fileBrowser, which will be the label of the dialog
//$FTM_BrowseType Pass to fileBrowser, which will define to get dialog for file or folder
{
global string $FTM_WorkSpace;
if (size($FTM_WorkSpace) == 0)
{
$FTM_WorkSpace = `workspace -q -rd` + `workspace -q -rte "sourceImages"`;
$FTM_WorkSpace = `FTM_GetPath "path" $FTM_WorkSpace`;
}
workspace -dir $FTM_WorkSpace;

global int $FTM_NEW_MAYA;
if ($FTM_NEW_MAYA) { // use 'fileDialog2' for the browser command.
if ($FTM_BrowseType == 0) $FTM_BrowseType = 1;
else if ($FTM_BrowseType == 4) $FTM_BrowseType = 3;
string $return[] = `fileDialog2 -ds 2 -cap $FTM_WhichButton -dir $FTM_WorkSpace -fm $FTM_BrowseType -okc $FTM_WhichButton -cc "Cancel"`;
string $path = $return[0];
if (!size($path)) $path = `textFieldButtonGrp -q -text $FTM_TextField`;
if ($FTM_FileOrPath == "file") $path += "bugQuickFix";
FTM_ChangeTextField $FTM_FileOrPath $FTM_TextField $path "";
}
else {
string $FTM_Temp = "";
$FTM_Temp += "FTM_ChangeTextField ";
$FTM_Temp += ("\"" + $FTM_FileOrPath + "\" ");
$FTM_Temp += ("\"" + $FTM_TextField + "\" ");
fileBrowser $FTM_Temp $FTM_WhichButton "" $FTM_BrowseType;
}
}

///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//
//The callback command on fileBrowser.
//
global proc FTM_ChangeTextField (string $FTM_FileOrPath, string $FTM_TextField, string $FTM_File, string $FTM_FileType)
//$FTM_FileOrPath How to deal with the input path , will be pass to FTM_GetPath
//$FTM_TextField The name of the control need to be edited
//$FTM_File The file specified
//$FTM_FileType The file type specified
{
string $FTM_Path = `FTM_GetPath $FTM_FileOrPath $FTM_File`;
textFieldButtonGrp -e -text (toNativePath($FTM_Path)) $FTM_TextField;
//Close the dialog for IRIX/Linux.
string $os = `about -os`;
if (gmatch($os, "*irix*") || gmatch($os, "*linux*"))
window -e -vis false projectViewerWindow;

global string $FTM_WorkSpace;
$FTM_WorkSpace = $FTM_Path;
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
// Reset the UI to its initial state.
//
global proc FTM_ResetUI (string $FTM_OptionColumn,string $FTM_AnalysisColumn,string $FTM_ExtraFunctionColumn,string $FTM_Tabs,string $FTM_CopyButton,string $FTM_MoveButton,string $FTM_SetButton)
{
waitCursor -state on;

// The main window;
global int $FTM_WIDTH, $FTM_HEIGHT;
window -e -wh $FTM_WIDTH $FTM_HEIGHT FTM_MainWindow;

// Analyse area
text -e -l "Not analysed yet." ($FTM_AnalysisColumn + "|FTM_EmptyAnalysisText");

if (`columnLayout -q -ex ($FTM_AnalysisColumn + "|FTM_AnalysisCheckerColumn")`)
deleteUI ($FTM_AnalysisColumn + "|FTM_AnalysisCheckerColumn");

// Operation mode
radioButtonGrp -e -select 1 ($FTM_OptionColumn + "|FTM_OperationMode");
// Source directory field
textFieldButtonGrp -e -text "" -en 0 ($FTM_OptionColumn + "|FTM_SourceDirectoryField");
// Target directory field
string $FTM_CurrentProject = `workspace -q -rd`;
string $FTM_CurrentSourceImagesDir = $FTM_CurrentProject + `workspace -q -rte "sourceImages"`;
string $FTM_SourceImages = `FTM_GetPath "path" $FTM_CurrentSourceImagesDir`;
textFieldButtonGrp -e -text $FTM_SourceImages ($FTM_OptionColumn + "|FTM_TargetDirectoryField");
// Make new folder area
checkBoxGrp -e -v1 0 ($FTM_OptionColumn + "|FTM_MakeFolderChecker");
textFieldGrp -e -text "MyTextureFiles" -en 0 ($FTM_OptionColumn + "|FTM_NewFolderNameField");
// Add prefix area
checkBox -e -v 0 ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_AddPrefixChecker");
textField -e -text "prefix_" -en 0 ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField");
// Add suffix area
checkBox -e -v 0 ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_AddSuffixChecker");
textField -e -text "_suffix" -en 0 ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField");
// Replace string area
checkBoxGrp -e -v1 0 ($FTM_OptionColumn + "|FTM_ReplaceStringChecker");
textFieldGrp -e -text "OldString" -en 0 ($FTM_OptionColumn + "|FTM_OldStringField");
textFieldGrp -e -text "NewString" -en 0 ($FTM_OptionColumn + "|FTM_NewStringField");

// Extra function tab
textFieldButtonGrp -e -text "" ($FTM_ExtraFunctionColumn + "|oldRootField");
string $tmp = `workspace -q -rd` + `workspace -q -rte "sourceImages"`;
$tmp = `FTM_GetPath "path" $tmp`;
textFieldButtonGrp -e -text $tmp ($FTM_ExtraFunctionColumn + "|newRootField");
intFieldGrp -e -v1 1024 ($FTM_ExtraFunctionColumn + "|FTM_BOTRow|FTM_BOTResFieldGrp");
intFieldGrp -e -v1 1024 ($FTM_ExtraFunctionColumn + "|FTM_MAPRow|FTM_MAPResFieldGrp");
optionMenu -e -v "Mipmap" ($FTM_ExtraFunctionColumn + "|FTM_FilterTypeRow|FTM_FilterTypeMenu");
optionMenu -e -v "\*" ($FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCSourceMenu");
optionMenu -e -v "iff" ($FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCTargetMenu");
checkBox -e -v 0 ($FTM_ExtraFunctionColumn + "|FTM_SeqCheck");
checkBox -e -v 1 ($FTM_ExtraFunctionColumn + "|FTM_UpdateCheck");
checkBox -e -v 0 -en 1 ($FTM_ExtraFunctionColumn + "|FTM_RemoveCheck");

// Return to the first tab
tabLayout -e -sti 1 $FTM_Tabs;

// Reset all bottom function buttons
button -e -en 1 $FTM_CopyButton;
button -e -en 1 $FTM_MoveButton;
button -e -en 1 $FTM_SetButton;

global string $FTM_WorkSpace;
$FTM_WorkSpace = `workspace -q -rd` + `workspace -q -rte "sourceImages"`;
$FTM_WorkSpace = `FTM_GetPath "path" $FTM_WorkSpace`;

select -cl;
waitCursor -state off;
}

//////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
//
// The Copy, Move and Set functions.
//
global proc FTM_Function (string $FTM_Function, string $FTM_OptionColumn)
{
global string $lsCmd;
string $FTM_SelectedFiles[] = eval($lsCmd + " -sl");
if (`FTM_SelCheck $FTM_SelectedFiles`)
{
waitCursor -state on;
FTM_Log "start" "" "";
int $wrong = 0;
// First get elements ready.
int $FTM_OperationMode = `radioButtonGrp -q -select ($FTM_OptionColumn + "|FTM_OperationMode")`;

// Source directory.
string $FTM_SourceDirectory;

// Target directory.
string $FTM_TargetDirectory = `textFieldButtonGrp -q -text ($FTM_OptionColumn + "|FTM_TargetDirectoryField")`;
$FTM_TargetDirectory = `FTM_GetPath "path" $FTM_TargetDirectory`;
// Check if new folder needed. If needed, create one only when the folder does not exist.
if ( `checkBoxGrp -q -v1 ($FTM_OptionColumn + "|FTM_MakeFolderChecker")` )
{
string $FTM_NewFolderName = `textFieldGrp -q -text ($FTM_OptionColumn + "|FTM_NewFolderNameField")`;
$FTM_TargetDirectory = $FTM_TargetDirectory + $FTM_NewFolderName;
if (!`file -q -ex $FTM_TargetDirectory`) {
if (`sysFile -md $FTM_TargetDirectory`)
FTM_Log "" ("Folder created: \"" + (toNativePath($FTM_TargetDirectory)) + "\".") "";
else {
$wrong = 1;
FTM_Log "" ("Folder can not be created: " + (toNativePath($FTM_TargetDirectory)) + "\".") "";
}
}
else {
if (!`filetest -w $FTM_TargetDirectory`) {
$wrong = 1;
FTM_Log "" ("Folder exists but is not writeable: " + (toNativePath($FTM_TargetDirectory)) + "\".") "";
}
}
$FTM_TargetDirectory = `FTM_GetPath "path" $FTM_TargetDirectory`;
}

if (!$wrong) {
// Define command for function.
string $FTM_FunctionCmd;
if ($FTM_Function == "Copy")
$FTM_FunctionCmd = "sysFile -cp ";
else if ($FTM_Function == "Move")
$FTM_FunctionCmd = "sysFile -mov ";

// base of progress feedback setup
int $progress = 0;
int $percentage = 0;
progressWindow -t "FTM Working..." -pr $progress -ii 1 -min 0 -max `size $FTM_SelectedFiles`;

// Execute command of current function for every file texture node selected.
for ($FTM_SelectedFile in $FTM_SelectedFiles)
{
FTM_Log "" ($FTM_SelectedFile+":") "";
if ( `progressWindow -q -ic` ){
FTM_Log "" "User cancelled." "";
break;
}
$wrong = 0;
// Check if the dialog has been cancelled
$progress += 1;
$percentage = $progress * (100/size($FTM_SelectedFiles));
progressWindow -e -pr $progress -st ("Handling " + $FTM_SelectedFile + " ...... " + $percentage + "%");

// start to work
string $FTM_CurrentFile = `getAttr ($FTM_SelectedFile + ".fileTextureName")`;
string $FTM_SourceFile[] = `FTM_GetFile $FTM_CurrentFile`;
string $FTM_OriginSourceFile = $FTM_SourceFile[1];

// The file texture is not specified.
if (size($FTM_OriginSourceFile) == 0)
FTM_Log "" "" "WARNING: File texture is not specified.";
// The file texture is specified.
else
{

// If replace string was selected, replace the string specified.
if ( `checkBoxGrp -q -v1 ($FTM_OptionColumn + "|FTM_ReplaceStringChecker")` )
{
string $FTM_OldString = `textFieldGrp -q -tx ($FTM_OptionColumn + "|FTM_OldStringField")`;
string $badChar[] = {"+",".","^","$","[","]","(",")"};
for ($char in $badChar)
$FTM_OldString = `substituteAllString $FTM_OldString $char ("\\"+$char)`;
string $FTM_MatchExpression = "(" + $FTM_OldString + ")+";
string $FTM_NewString = `textFieldGrp -q -tx ($FTM_OptionColumn + "|FTM_NewStringField")`;
for ($i=0; $i<size($FTM_SourceFile[1]); $i++)
$FTM_SourceFile[1] = `substitute $FTM_MatchExpression $FTM_SourceFile[1] $FTM_NewString`;
}

// Add prefix or(and) append suffix.
string $FTM_Prefix;
string $FTM_Suffix;
string $FTM_SourceFileRegularName[] = `FTM_FCFileRegularName $FTM_SourceFile[1]`;
// If prefix was set, add it to the file name.
if ( `checkBox -q -v ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_AddPrefixChecker")` )
$FTM_Prefix = `textField -q -tx ($FTM_OptionColumn + "|FTM_AddPrefixRow|FTM_PrefixField")`;
// If suffix was set, append it to the file name.
if ( `checkBox -q -v ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_AddSuffixChecker")` )
$FTM_Suffix = `textField -q -tx ($FTM_OptionColumn + "|FTM_AddSuffixRow|FTM_SuffixField")`;

// Assemble the filename
if (size($FTM_SourceFileRegularName[1]))
$FTM_SourceFileRegularName[1] = "." + $FTM_SourceFileRegularName[1];
if (size($FTM_SourceFileRegularName[2]))
$FTM_SourceFileRegularName[2] = "." + $FTM_SourceFileRegularName[2];
$FTM_SourceFile[1] = $FTM_Prefix + $FTM_SourceFileRegularName[0] + $FTM_Suffix + $FTM_SourceFileRegularName[1] + $FTM_SourceFileRegularName[2];

// Function process.
string $FTM_FinalCmd;
string $FTM_FunctionResult;
int $setWrong = 0;
if ($FTM_Function != "Set")
{
if ($FTM_OperationMode == 1)
{
$FTM_FinalCmd = $FTM_FunctionCmd + "\"" + `substituteAll "\\\\" ($FTM_TargetDirectory + $FTM_SourceFile[1]) "/"` + "\" \"" + `substituteAll "\\\\" $FTM_SourceFile[0] "/"` + "\"";
$FTM_FunctionResult = $FTM_Function + " \"" + `toNativePath $FTM_SourceFile[0]` + "\" to \"" + `toNativePath ($FTM_TargetDirectory + $FTM_SourceFile[1])` + "\". ";
}
else if ($FTM_OperationMode == 2)
{
$FTM_SourceDirectory = `textFieldButtonGrp -q -text ($FTM_OptionColumn + "|FTM_SourceDirectoryField")`;
$FTM_SourceDirectory = `FTM_GetPath "path" $FTM_SourceDirectory`;
$FTM_FinalCmd = $FTM_FunctionCmd + "\"" + `substituteAll "\\\\" ($FTM_TargetDirectory + $FTM_SourceFile[1]) "/"` + "\" \"" + `substituteAll "\\\\" ($FTM_SourceDirectory + $FTM_OriginSourceFile) "/"` + "\"";
$FTM_FunctionResult = $FTM_Function + " \"" + `toNativePath ($FTM_SourceDirectory + $FTM_OriginSourceFile)` + "\" to \"" + `toNativePath ($FTM_TargetDirectory + $FTM_SourceFile[1])` + "\". ";
}
}
else if ($FTM_Function == "Set")
{
string $path = `substituteAll "\\\\" ($FTM_TargetDirectory + $FTM_SourceFile[1]) "/"`;
string $cmd = "setAttr -typ \"string\" " + $FTM_SelectedFile + ".fileTextureName \"" + $path + "\"";
if (catchQuiet(eval($cmd))) {
$FTM_FunctionResult = "Attribute \"fileTextureName\" is locked/connected and can NOT be modified!";
$setWrong = 1;
}
else
$FTM_FunctionResult = "Set to \"" + `toNativePath ($FTM_TargetDirectory + $FTM_SourceFile[1])` + "\". ";
}

// Do the function.
if ($FTM_Function != "Set") {
if (!eval($FTM_FinalCmd)) {
$wrong = 1;
FTM_Log "" "" ("WARNING: " + $FTM_Function + " can NOT be done, could be permission issue or path existence issue.");
}
}
if (!$wrong) {
// Print the function result.
if ( `file -q -ex ($FTM_TargetDirectory + $FTM_SourceFile[1])` )
{
if ($FTM_Function == "Move")
{
// File copied but not removed -- not actually "move".
if ( `file -q -ex $FTM_SourceFile[0]` || `file -q -ex ($FTM_SourceDirectory + $FTM_OriginSourceFile)`)
{
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult + " But the original file is not removed. Check the HELP for possible reasons.";
FTM_Log "" "" ("WARNING: " + $FTM_FunctionResult);
}
else
{
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult;
FTM_Log "" "" $FTM_FunctionResult;
}
}
else
{
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult;
FTM_Log "" "" $FTM_FunctionResult;
}
}
else
{
if ($FTM_Function == "Set") {
if ($setWrong)
$FTM_FunctionResult = "WARNING: " + $FTM_FunctionResult;
else
$FTM_FunctionResult = "Succeed: " + $FTM_FunctionResult + "But destination does NOT exist.";
}
else if ($FTM_Function != "Set")
$FTM_FunctionResult = "Fail: " + $FTM_FunctionResult + "Check Help tab for possible reasons.";
FTM_Log "" "" $FTM_FunctionResult;
}
}
}
}
}

// finish progress feed back
progressWindow -ep;
// job done
FTM_Log "end" "" "";
FTM_END;
waitCursor -state off;
}
}

/////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////
//
//Build the main UI.
//
global proc FileTextureManager ()
{
////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////
//
// Version Check
//
float $verCut = 2010;
global int $FTM_NEW_MAYA, $FTM_WIDTH, $FTM_HEIGHT;
$FTM_NEW_MAYA = 0;
$FTM_WIDTH = 380;
$FTM_HEIGHT = 600;

string $verString = `about -v`;
string $verString_tmp[];
tokenize $verString " " $verString_tmp;
float $verNum = $verString_tmp[0];
if ($verNum > $verCut) { // version newer than 2010
global int $FTM_NEW_MAYA, $FTM_WIDTH, $FTM_HEIGHT;
$FTM_NEW_MAYA = 1;
$FTM_WIDTH = 520;
$FTM_HEIGHT = 700;
}
// array of formats supported by format conversion function
global string $FTM_FCAllFormats[];
$FTM_FCAllFormats = {"iff","sgi","tga","rgb","jpg","jpeg","map","tif","tiff","bmp","bw","icon","cin","pic","yuv","als","gif","lff","pxb","scn","ppm","pri","qtl","vst","rla"};

// cover all file texture nodes including mentalray's
global string $lsCmd;
$lsCmd = "ls -typ file -typ psdFileTex ";

select -cl;

global string $FTM_MayaWorkSpace;
$FTM_MayaWorkSpace = `workspace -q -dir`;
global string $FTM_WorkSpace = "";

//Make sure the window will be displayed in proper size.
windowPref -enableAll false;
//If the UI exits , delete it.
if (`window -exists FTM_MainWindow`)
deleteUI FTM_MainWindow;
//Build a new UI.
global int $FTM_WIDTH, $FTM_HEIGHT;
window -title "File Texture Manager" -wh $FTM_WIDTH $FTM_HEIGHT -tlc 200 200 -ret FTM_MainWindow;
string $FTM_MainForm = `formLayout`;
string $FTM_Tabs = `tabLayout -imw 0 -imh 0`;
//Option tab
string $FTM_OptionForm = `formLayout`;
string $FTM_OptionScroll = `scrollLayout -cr true`;
string $FTM_OptionColumn = `columnLayout -adj 1 -rs 5`;
//Analyse area
formLayout -nd 100 FTM_AnalyseForm;
string $FTM_AnalyseColumn = `columnLayout -cat both 30 -adj 1 -rs 5`;
button -l "分析场景文件纹理" -h 30 -w 250 FTM_AnalyseButton;
text -l "" -h 5;
text -l "Select files you want to manage. <Multi-Selectable>";
string $FTM_AnalysisScroll = `scrollLayout -p FTM_AnalyseForm`;
string $FTM_AnalysisColumn = `columnLayout -cat left 15`;
text -l "Not analysed yet." FTM_EmptyAnalysisText;
button -e -c ("FTM_AnalyseFileTextures " + $FTM_AnalysisColumn) ($FTM_AnalyseColumn + "|FTM_AnalyseButton");
formLayout -e
-af $FTM_AnalyseColumn left 0
-af $FTM_AnalyseColumn right 0
-af $FTM_AnalyseColumn top 5
-af $FTM_AnalyseColumn bottom 200
-ac $FTM_AnalysisScroll top 5 $FTM_AnalyseColumn
-af $FTM_AnalysisScroll bottom 0
-af $FTM_AnalysisScroll left 0
-af $FTM_AnalysisScroll right 0
($FTM_OptionColumn + "|FTM_AnalyseForm");
setParent $FTM_OptionColumn;
separator -style "in" -h 10;
//Operation mode
radioButtonGrp -l "Operation Mode" -la2 "Automatic" "Manual" -nrb 2 -select 1 -cl3 right left left -cw3 120 100 100 FTM_OperationMode;

separator -style "in" -h 5;

//Set source directory area
textFieldButtonGrp -label "Source Directory" -text "" -buttonLabel "Browse..." -adj 2 -en 0 -cw 1 120 -cw 3 60 -cl3 right left center FTM_SourceDirectoryField;

separator -style "in" -h 5;

//Set target directory area
string $FTM_CurrentProject = `workspace -q -rd`;
string $FTM_CurrentSourceImagesDir = $FTM_CurrentProject + `workspace -q -fileRuleEntry "sourceImages"`;
string $FTM_SourceImages = `FTM_GetPath "path" $FTM_CurrentSourceImagesDir`;
textFieldButtonGrp -label "Target Directory" -text $FTM_SourceImages -buttonLabel "Browse..." -adj 2 -cw 1 120 -cw 3 60 -cl3 right left center FTM_TargetDirectoryField;
//Create new folder area
checkBoxGrp -ncb 1 -l1 "Make New Folder Under Target Directory" -adj 1 -v1 0 -cat 1 left 101 FTM_MakeFolderChecker;
textFieldGrp -label "Folder Name" -text "MyTextureFiles" -en 0 -cw2 120 180 -cl2 right left FTM_NewFolderNameField;
text -al center -l "The FINAL target directory will be equal to target directory";
text -al center -l "plus the new folder if user decide to make a new folder";
separator -style "in" -h 5;
//Update texture file area
rowLayout -nc 2 -cw 1 120 -cat 1 right 0 -cl2 left left FTM_AddPrefixRow;
checkBox -l "Add Prefix" -v 0 FTM_AddPrefixChecker;
textField -tx "prefix_" -en 0 -w 150 FTM_PrefixField;
setParent $FTM_OptionColumn;
rowLayout -nc 2 -cw 1 120 -cat 1 right 0 -cl2 left left FTM_AddSuffixRow;
checkBox -l "Add Suffix" -v 0 FTM_AddSuffixChecker;
textField -tx "_suffix" -en 0 -w 150 FTM_SuffixField;
setParent $FTM_OptionColumn;
checkBoxGrp -ncb 1 -l1 "Replace String" -adj 1 -v1 0 -cat 1 left 101 FTM_ReplaceStringChecker;
textFieldGrp -l "Old String" -tx "OldString" -en 0 -cw2 120 150 -cl2 right left FTM_OldStringField;
textFieldGrp -l "New String" -tx "NewString" -en 0 -cw2 120 150 -cl2 right left FTM_NewStringField;
formLayout -e
-af $FTM_OptionScroll top 5
-af $FTM_OptionScroll left 0
-af $FTM_OptionScroll right 0
-af $FTM_OptionScroll bottom 0
$FTM_OptionForm;
setParent $FTM_Tabs;
//Extra function tab
string $FTM_ExtraFunctionScroll = `scrollLayout -cr true`;
string $FTM_ExtraFunctionColumn = `columnLayout -cat both 15 -adj 1 -rs 5`;
// Substitute path root area
separator -style "none" -h 5;
text -fn "boldLabelFont" -al left -l "Substitute path root";
textFieldButtonGrp -l "Old Root" -text "" -buttonLabel "Browse..." -adj 2 -en 1 -cw 1 80 -cw 3 60 -cl3 right left center oldRootField;
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"path\" " + $FTM_ExtraFunctionColumn + "|oldRootField \"Choose old root\" 4") ($FTM_ExtraFunctionColumn + "|oldRootField");
string $tmp = `workspace -q -rd` + `workspace -q -fileRuleEntry "sourceImages"`;
$tmp = `FTM_GetPath "path" $tmp`;
textFieldButtonGrp -l "New Root" -text $tmp -buttonLabel "Browse..." -adj 2 -en 1 -cw 1 80 -cw 3 60 -cl3 right left center newRootField;
textFieldButtonGrp -e -bc ("FTM_BrowseCmd \"path\" " + $FTM_ExtraFunctionColumn + "|newRootField \"Choose new root\" 4") ($FTM_ExtraFunctionColumn + "|newRootField");
button -h 25 -l "Substitute" -c ("FTM_Substitute " + $FTM_ExtraFunctionColumn + "|oldRootField " + $FTM_ExtraFunctionColumn + "|newRootField");
// BOT setup area
separator -style "in" -h 10;
text -fn "boldLabelFont" -al left -l "Memory Efficiency (Maya 'file' nodes only)";
//text -fn "boldLabelFont" -al left -l "BOT Setup (Maya sw renderer only)";
text -al left -l "\"BOT\" Setup (Maya sw renderer only)";
rowLayout -nc 3 -adj 3
-cw 1 170 -cw 2 2 -cal 3 center
-cat 1 both 0 -cat 3 both 0
-rat 1 bottom 0 -rat 2 bottom 0 -rat 3 bottom 0
FTM_BOTRow;
intFieldGrp -nf 1 -adj 2 -cw 1 50 -cat 1 left 0 -cat 2 both 5 -l "Threshold" -el "" -v1 1024 FTM_BOTResFieldGrp;
text -l "";
button -h 25 -l "Setup BOT" -c ("FTM_BOTSetup 1 " + $FTM_ExtraFunctionColumn);
setParent ..;
button -h 25 -l "Unset BOT" -c ("FTM_BOTSetup 0 " + $FTM_ExtraFunctionColumn);
text -al left -l "\".map\" Setup (mentalray only)";
rowLayout -nc 3 -adj 3
-cw 1 170 -cw 2 2 -cal 3 center
-cat 1 both 0 -cat 3 both 0
-rat 1 bottom 0 -rat 2 bottom 0 -rat 3 bottom 0
FTM_MAPRow;
intFieldGrp -nf 1 -adj 2 -cw 1 50 -cat 1 left 0 -cat 2 both 5 -l "Threshold" -el "" -v1 1024 FTM_MAPResFieldGrp;
text -l "";
button -h 25 -l "Setup .map" -c ("FTM_MAPSetup 1 " + $FTM_ExtraFunctionColumn);
setParent ..;
button -h 25 -l "Unset .map" -c ("FTM_MAPSetup 0 " + $FTM_ExtraFunctionColumn);
// Filter setup area
separator -style "in" -h 10;
text -fn "boldLabelFont" -al left -l "Filter setup (Maya 'file'/'psdFileTex' nodes only)";
rowLayout -nc 2 -cw 1 120 -cat 2 left 30 -adj 2 -cal 2 center -rat 1 bottom 0 FTM_FilterTypeRow;
optionMenu -l "Filter Type" FTM_FilterTypeMenu;
menuItem -label "Off";
menuItem -label "Mipmap";
menuItem -label "Box";
menuItem -label "Quadratic";
menuItem -label "Quartic";
menuItem -label "Gaussian";
optionMenu -e -v "Mipmap" ($FTM_ExtraFunctionColumn + "|FTM_FilterTypeRow|FTM_FilterTypeMenu");
button -h 25 -l "Set Filter Type" -c ("FTM_FilterSetup " + $FTM_ExtraFunctionColumn);
setParent ..;
// Format conversion area
separator -style "in" -h 10;
text -fn "boldLabelFont" -al left -l "Texture file format conversion";
rowLayout -nc 3 -cw 1 80 -cw 3 80 -cat 1 left 0 -cat 2 left 10 -cat 3 left 10 -adj 2 -cal 2 center FTM_FCRow;
optionMenu -l "From" FTM_FCSourceMenu;
menuItem -label "\*";
global string $FTM_FCAllFormats[];
for ($i=0;$i<size($FTM_FCAllFormats);$i++)
menuItem -label $FTM_FCAllFormats[$i];
button -h 25 -l "Select Matches" -c ("select -r `FTM_FCGetMatches \"" + $FTM_ExtraFunctionColumn + "|FTM_FCRow|FTM_FCSourceMenu\"`;");
optionMenu -l "To" FTM_FCTargetMenu;
for ($i=0;$i<size($FTM_FCAllFormats);$i++)
menuItem -label $FTM_FCAllFormats[$i];
setParent ..;
checkBox -l "Handle sequence textures." -al "left" -v 0 FTM_SeqCheck;
checkBox -l "Update path info." -al "left" -v 1 FTM_UpdateCheck;
checkBox -l "Remove original textures. Use with caution!" -al "left" -v 0 -en 1 FTM_RemoveCheck;
checkBox -e -onc ("checkBox -e -en 1 " + $FTM_ExtraFunctionColumn + "|FTM_RemoveCheck")
-ofc ("checkBox -e -en 0 " + $FTM_ExtraFunctionColumn + "|FTM_RemoveCheck")
($FTM_ExtraFunctionColumn + "|FTM_UpdateCheck");
button -l "Convert" -h 25 -c ("FTM_FCGatherInfo " + $FTM_ExtraFunctionColumn);
setParent $FTM_Tabs;
//Help tab
string $FTM_HelpForm = `formLayout`;
//Description area
scrollField -ww true -editable false FTM_HelpField;
//About FileTextureManager
setParent $FTM_HelpForm;
global int $FTM_NEW_MAYA;
string $FTM_AboutFrame;
if ($FTM_NEW_MAYA) $FTM_AboutFrame = `frameLayout -l "About FileTextureManager" -fn boldLabelFont -cll 0 -bv true -li 5`;
else $FTM_AboutFrame = `frameLayout -l "About FileTextureManager" -la top -fn boldLabelFont -cll 0 -bv true -li 5`;
string $FTM_AboutForm = `formLayout`;
string $FTM_AboutTextLeft = `text -l "Script Name :\nUpdated :\nAuthor :\nContact :\n\nAll Rights Reserved." -al left`;
string $FTM_AboutTextRight = `text -l "FileTextureManager.mel\nMay, 2011\nCrow Yeh ( YE Feng )\nCrow.Yeh@gmail.com" -al left`;
formLayout -e
-af $FTM_AboutTextLeft left 10
-af $FTM_AboutTextLeft top 5
-an $FTM_AboutTextLeft right
-af $FTM_AboutTextLeft bottom 5
-ac $FTM_AboutTextRight left 10 $FTM_AboutTextLeft
-af $FTM_AboutTextRight top 5
-an $FTM_AboutTextRight right
-an $FTM_AboutTextRight bottom
$FTM_AboutForm;
formLayout -e
-ac FTM_HelpField bottom 5 $FTM_AboutFrame
-af FTM_HelpField top 5
-af FTM_HelpField left 0
-af FTM_HelpField right 0
-an $FTM_AboutFrame top
-af $FTM_AboutFrame left 0
-af $FTM_AboutFrame right 0
-af $FTM_AboutFrame bottom 0
$FTM_HelpForm;
//Function form.
setParent $FTM_MainForm;
string $FTM_FunctionForm = `formLayout -h 30 -numberOfDivisions 100`;
string $FTM_CopyButton = `button -l "复制"
-c ("FTM_Function \"Copy\" " + $FTM_OptionColumn)`;
string $FTM_MoveButton = `button -l "剪切"
-c ("FTM_Function \"Move\" " + $FTM_OptionColumn)`;
string $FTM_SetButton = `button -l "指定"
-c ("FTM_Function \"Set\" " + $FTM_OptionColumn)`;
string $FTM_ResetButton = `button -l "重置FTM" -c ("FTM_ResetUI "+$FTM_OptionColumn+" "+$FTM_AnalysisColumn+" "+$FTM_ExtraFunctionColumn+" "+$FTM_Tabs+" "+$FTM_CopyButton+" "+$FTM_MoveButton+" "+$FTM_SetButton)`;
string $FTM_CloseButton = `button -l "退出"
-c ("deleteUI FTM_MainWindow; select -cl;global string $FTM_MayaWorkSpace; workspace -dir $FTM_MayaWorkSpace;")`;
formLayout -e
-ap $FTM_CopyButton right 1 20
-af $FTM_CopyButton top 0
-af $FTM_CopyButton left 0
-af $FTM_CopyButton bottom 0
-ap $FTM_MoveButton left 1 20
-ap $FTM_MoveButton right 1 40
-af $FTM_MoveButton top 0
-af $FTM_MoveButton bottom 0
-ap $FTM_SetButton left 1 40
-ap $FTM_SetButton right 1 60
-af $FTM_SetButton top 0
-af $FTM_SetButton bottom 0
-af $FTM_ResetButton top 0
-af $FTM_ResetButton bottom 0
-ap $FTM_ResetButton left 1 60
-ap $FTM_ResetButton right 1 80
-ap $FTM_CloseButton left 1 80
-af $FTM_CloseButton top 0
-af $FTM_CloseButton right 0
-af $FTM_CloseButton bottom 0
$FTM_FunctionForm;
formLayout -e
-af $FTM_Tabs top 0
-af $FTM_Tabs left 0
-af $FTM_Tabs right 0
-ac $FTM_Tabs bottom 3 $FTM_FunctionForm
-af $FTM_FunctionForm left 0
-af $FTM_FunctionForm right 0
-af $FTM_FunctionForm bottom 0
-an $FTM_FunctionForm top
$FTM_MainForm;

FTM_EditUIControl $FTM_OptionColumn $FTM_HelpForm;


string $tabCC = "button -e -en 0 " + $FTM_CopyButton + ";";
$tabCC += "button -e -en 0 " + $FTM_MoveButton + ";";
$tabCC += "button -e -en 0 " + $FTM_SetButton + ";";
$tabCC += "if (`tabLayout -q -sti " + $FTM_Tabs + "` == 1) {";
$tabCC += "button -e -en 1 " + $FTM_CopyButton + ";";
$tabCC += "button -e -en 1 " + $FTM_MoveButton + ";";
$tabCC += "button -e -en 1 " + $FTM_SetButton + ";";
$tabCC += "}";

tabLayout -e -tl $FTM_OptionForm "BasicFunctions" -tl $FTM_ExtraFunctionScroll "ExtraFunctions" -tl $FTM_HelpForm "Help" -psc $tabCC $FTM_Tabs;
showWindow FTM_MainWindow;
//Make sure other windows will be displayed in proper size.
windowPref -enableAll true;
}

FileTextureManager;
/////////////////
// SCRIPT Ends //
/////////////////