-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrenamer_Sid.txt
198 lines (195 loc) · 8.84 KB
/
renamer_Sid.txt
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
global proc Sid_rename_tool () { if (`window -q -exists Sid_rename_toolWindow`) deleteUI Sid_rename_toolWindow;
//UI taken from qkRename
window -s 0 -title "Sid_rename_tool" -maximizeButton 0 -minimizeButton 1 Sid_rename_toolWindow;
columnLayout;
rowColumnLayout -numberOfColumns 1 -columnWidth 1 313 ;
textFieldGrp -label "Rename:" -text "" -columnWidth 1 70 -columnWidth 2 235 KK_RenameRenameTFG;
rowColumnLayout -numberOfColumns 2 -columnWidth 1 130 -columnWidth 2 170;
intFieldGrp -label "Start #:" -v1 1 -columnWidth 1 68 -columnWidth 2 60 KK_RenameStartIFG;
intFieldGrp -label "Padding:" -v1 2 -columnWidth 1 64 -columnWidth 2 60 KK_RenamePaddingIFG;
setParent..;
rowColumnLayout -numberOfColumns 1 -columnWidth 1 306 ;
button -h 23 -w 100 -l "Rename and Number" -bgc 0.3 0.2 0.2 -c "Rename_SidName(3)";
setParent..;
separator -style "in" -w 315 ;
rowColumnLayout -numberOfColumns 3 -cs 1 10 -cs 3 4 -columnWidth 1 84 -columnWidth 2 104 -columnWidth 3 104;
text -label "Remove..." -align "left";
button -h 23 -w 60 -l "First Character-->" -bgc 0.3 0.2 0.2 -c "remove_FirstChr()";
button -h 23 -w 60 -l "<--Last Character" -bgc 0.3 0.2 0.2 -c "remove_LastChr()";
setParent..;
rowColumnLayout -numberOfColumns 3 -cs 1 10 -columnWidth 1 70 -columnWidth 2 170 -columnWidth 3 56;
text -l " Hash Rename:";
textFieldGrp -label "" -text "name_####_suffix" -columnWidth 1 10 -columnWidth 2 153 Rename_js_hashRenameTFG;
button -h 23 -w 48 -l "Rename" -bgc 0.3 0.2 0.2 -c "Rename_js_hashRename_MainProc()";
setParent..;
separator -style "in" -w 315 ;
rowColumnLayout -numberOfColumns 3 -cs 1 10 -columnWidth 1 55 -columnWidth 2 185 -columnWidth 3 56;
text -l "(Before)";
textFieldGrp -label "" -text "prefix_" -columnWidth 1 10 -columnWidth 2 168 prefixTFG;
button -h 21 -l "Add" -bgc 0.3 0.2 0.2 -c "Rename_SidName(1)";
setParent..;
text -l "" -h 1;
rowColumnLayout -numberOfColumns 3 -cs 1 10 -columnWidth 1 55 -columnWidth 2 185 -columnWidth 3 56;
text -l "(After)";
textFieldGrp -label "" -text "_suffix" -columnWidth 1 10 -columnWidth 2 168 suffixTFG;
button -h 21 -l "Add" -bgc 0.3 0.2 0.2 -c "Rename_SidName(2)";
setParent..;
separator -style "in" -w 315 ;
rowColumnLayout -numberOfColumns 5 -columnWidth 1 61 -columnWidth 2 61 -columnWidth 3 61 -columnWidth 4 61 -columnWidth 5 62;
button -l "grp" -bgc 0.3 0.2 0.2 -c "SidSuffix _grp";
button -l "geo" -bgc 0.3 0.2 0.2 -c "SidSuffix _geo";
button -l "ctl" -bgc 0.3 0.2 0.2 -c "SidSuffix _ctl";
button -l "jnt" -bgc 0.3 0.2 0.2 -c "SidSuffix _jnt";
button -l "drv" -bgc 0.3 0.2 0.2 -c "SidSuffix _drv";
setParent ..;
separator -style "in" -w 315 ;
rowColumnLayout -numberOfColumns 1 -columnWidth 1 313 ;
textFieldGrp -label "Search:" -text "pasted_" -columnWidth 1 70 -columnWidth 2 233 SearchAndReplace_SearchTFG;
textFieldGrp -label "Replace:" -text "" -columnWidth 1 70 -columnWidth 2 233 SearchAndReplace_ReplaceTFG;
radioButtonGrp -bgc 0.15 0.25 0.15 -numberOfRadioButtons 3 -label "" -sl 1 -labelArray3 "Hierarchy" "Selected" "All" -columnWidth 1 30 SearchAndReplace_OptionRBG;
rowColumnLayout -numberOfColumns 1 -columnWidth 1 305 ;
button -h 23 -w 40-l "Apply" -bgc 0.3 0.2 0.2 -c "SearchAndRename()";
setParent..;
setParent..;
window -e -wh 313 302 Sid_rename_toolWindow;
showWindow Sid_rename_toolWindow;
} global proc remove_LastChr() { string $jointSelected[0]= `ls -sl -long`;
int $jointSelectedSize = size($jointSelected);
for ($i=$jointSelectedSize-1;
$i >= 0;
$i--) { string $obj = $jointSelected[$i];
string $pathNodes[];
int $numTokens = tokenize($obj, "|", $pathNodes);
string $myObj = $pathNodes[$numTokens - 1];
int $stringSize = size($myObj);
if ($stringSize > 1) { string $newName = `substring $myObj 1 ($stringSize - 1)`;
rename $obj $newName;
} } } global proc remove_FirstChr() { string $jointSelected[0]= `ls -sl -long`;
int $jointSelectedSize = size($jointSelected);
for ($i=$jointSelectedSize-1;
$i >= 0;
$i--) { string $obj = $jointSelected[$i];
string $pathNodes[];
int $numTokens = tokenize($obj, "|", $pathNodes);
string $myObj = $pathNodes[$numTokens - 1];
int $stringSize = size($myObj);
if ($stringSize > 1) { string $newName = `substring $myObj 2 $stringSize`;
rename $obj $newName;
} } } global proc KK_RenameSelectedShape() { string $objects[] = `ls -sl`;
string $objTransform;
for ($objTransform in $objects) { string $shapes[] = `listRelatives -s -f $objTransform`;
string $pathTransNodes[];
int $numTokens = tokenize($objTransform, "|", $pathTransNodes);
string $myTransObj = $pathTransNodes[$numTokens - 1];
string $obj;
int $num = 1;
for ($obj in $shapes) { string $newShapeName = ($myTransObj + "_Shape" + $num);
rename $obj $newShapeName;
$num += 1;
} } } global proc SearchAndRename()
{ string $search = `textFieldGrp -q -tx SearchAndReplace_SearchTFG`;
string $replace = `textFieldGrp -q -tx SearchAndReplace_ReplaceTFG`;
string $options = `radioButtonGrp -q -sl SearchAndReplace_OptionRBG`;
if ($options == 1) { searchReplaceNames $search $replace "hierarchy";
} else if ($options == 2) { searchReplaceNames $search $replace "selected";
} else if ($options == 3) { searchReplaceNames $search $replace "all";
} } global proc SidSuffix(string $suffix) {string $jointSelected[0]= `ls -sl -long`;
int $jointSelectedSize = size($jointSelected);
for ($i=$jointSelectedSize-1;
$i >= 0;
$i--) { string $obj = $jointSelected[$i];
string $pathNodes[];
int $numTokens = tokenize($obj, "|", $pathNodes);
string $myObj = $pathNodes[$numTokens - 1];
rename $obj ($myObj + $suffix);
} } global proc Rename_js_hashRename_MainProc() { string $search = `textFieldGrp -q -tx Rename_js_hashRenameTFG`;
if ($search != "") { evalEcho ("Rename_js_hashRename \"" + $search + "\"");
} } global proc string Rename_js_replaceHash (string $string, int $number) { string $result;
string $substring = "#+";
$substring = `match $substring $string`;
string $substringNum = substituteAllString($substring, "#", "0");
string $numString = $number;
string $newString = ($substringNum + $numString);
int $fullSize =`size($newString)`;
int $numSize = `size($numString)`;
if ($numSize < size($substringNum)) { $numSize = $numSize+1;
$numString = `substring $newString $numSize $fullSize`;
} $result = `substitute $substring $string $numString`;
return $result;
} global proc string[] Rename_js_hashRename (string $newName) { string $objs[0];
int $count = 0;
string $return[0];
$objs = `ls -sl`;
if (size($objs) > 0) { $node = `createNode unknown`;
addAttr -ln "selObjects" -at message -multi -im 0;
for ($obj in $objs) { connectAttr -na ($obj + ".message") ($node + ".selObjects");
} $con = `listConnections ($node + ".selObjects")`;
for ($x = 0;
$x < size($con);
$x++) { string $tmp[0];
$tmp = `listConnections ($node + ".selObjects["+$x+"]")`;
string $object = $tmp[0];
$name = `Rename_js_replaceHash $newName ($x + 1)`;
$result = `rename $object $name`;
print ("// Renamed: " + $object + " --> " + $result + "\n");
} $return = `listConnections ($node + ".selObjects")`;
delete $node;
} if ((`size $return`) > 0) select $return;
return $return;
} proc string getShortName(string $obj) { string $ret = "";
if ($obj == "") return $ret;
string $parts[];
int $cnt = tokenize($obj, "|", $parts);
if ($cnt <= 0) $ret = $obj;
else $ret = $parts[($cnt-1)];
return $ret;
} proc string chop(string $str) { string $ret = "";
int $cnt = size($str);
if ($cnt <= 1) return $ret;
$ret = `substring $str 1 ($cnt-1)`;
return $ret;
} global proc Rename_SidName(int $mode) {string $objs[] = `ls -sl -long`;
int $objCnt = size($objs);
int $i;
string $prefix = `textFieldGrp -q -tx prefixTFG`;
string $suffix = `textFieldGrp -q -tx suffixTFG`;
string $rename = `textFieldGrp -q -tx KK_RenameRenameTFG`;
int $start = `intFieldGrp -q -v1 KK_RenameStartIFG`;
int $padding = `intFieldGrp -q -v1 KK_RenamePaddingIFG`;
string $shortName;
string $newShortName;
string $newName;
for ($i=0;
$i < $objCnt;
++$i) { $obj = $objs[$i];
$shortName = getShortName($obj);
switch ($mode) { case 1: if ($prefix == "") { warning -sl 0 ("Can't add prefix, prefix entry field is blank!");
return;
} $newShortName = ($prefix + $shortName);
break;
case 2: if ($suffix == "") { warning -sl 0 ("Can't add suffix, suffix entry field is blank!");
return;
} $newShortName = ($shortName + $suffix);
break;
case 3: if ($rename == "") { warning -sl 0 ("Can't rename and number, rename entry field is blank!");
return;
} int $n = $i + $start;
string $padStr = "";
for ($p=1;
$p < $padding;
++$p) { if ($n < pow(10, $p) ) $padStr += "0";
} $newShortName = ($rename+$padStr+$n);
break;
} $newName = `rename $obj $newShortName`;
select -r $newName;
string $newLongNames[] = `ls -sl -long`;
string $newLongName = $newLongNames[0];
for ($j=0;
$j < $objCnt;
++$j) { string $tmp = $objs[$j];
$tmp += "|";
$tmp = `substitute ($obj+"|") $tmp ("|"+$newLongName+"|")`;
$tmp = chop($tmp);
$objs[$j] = $tmp;
} } select $objs;
} Sid_rename_tool ()