forked from zclongpop123/BlackBox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkwRemoveNamespaces.mel
95 lines (83 loc) · 2.58 KB
/
kwRemoveNamespaces.mel
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
// Created by Kurt Wong @ 2005-4-20 9:18
// Created: 2005-4-22 16:31
// Updated: 11/17/2005 6:46PM
// ...
global proc kwRemoveNamespaces()
//
// DESCRIPTIONS:
// remove the namespace of selected hierachy or all the namespaces with nothing selected.
//
{
string $namespaces[];
string $sel[] = `ls -sl`;
//
if (!size($sel))
{
// get top-level namespaces
namespace -set ":";
$namespaces = `namespaceInfo -lon`;
$namespaces = stringArrayRemove({"UI"}, $namespaces);
for ($i=0; $i<size($namespaces); $i++) {
$namespaces[$i] = ":" + $namespaces[$i];
}
}
else
{
// get namespaces which contains selected objects
for ($obj in $sel)
{
string $namespace = `substitute "[^:]+$" $obj ""`;
if (size($namespace))
$namespaces[size($namespaces)] = ":" + $namespace;
}
}
// get all the sub-level namespaces
string $subNamespaces[] = $namespaces;
string $tmpNamespaces[];
string $tmpSubNamespaces[];
do {
$tmpNamespaces = {};
$tmpSubNamespaces = {};
for ($namespace in $subNamespaces) {
namespace -set $namespace;
$tmpSubNamespaces = `namespaceInfo -lon`;
for ($i=0; $i<size($tmpSubNamespaces); $i++) {
$tmpSubNamespaces[$i] = ":" + $tmpSubNamespaces[$i];
}
$tmpNamespaces = stringArrayCatenate($tmpNamespaces, $tmpSubNamespaces);
}
$namespaces = stringArrayCatenate($namespaces, $tmpNamespaces);
$subNamespaces = $tmpNamespaces;
}while (size($tmpNamespaces));
string $succeed[] = {};
string $failed[] = {};
// do with each nameSpace
for ($i=(size($namespaces)-1); $i>=0; $i--) {
namespace -set $namespaces[$i];
string $contents[] = `namespaceInfo -ls`;
namespace -set ":";
for ($obj in $contents) {
string $newName = `match "[^:]+$" $obj`;
string $stringAhead = `substitute "[^:]+$" $obj ""`;
string $ObjsWithSameName[] = `ls -l ($stringAhead + "*" + $newName)`;
for ($each in $ObjsWithSameName) {
// catch(`evalEcho("select -r " + $each)`);
// catch(`evalEcho("rename " + "\"" + $newName + "\"")`);
catch(evalEcho("rename \"" + $each + "\" \"" + $newName + "\""));
}
}
if (catch(`namespace -rm $namespaces[$i]`))
$failed[size($failed)] = $namespaces[$i];
else
$succeed[size($succeed)] = $namespaces[$i];
}
print "-------------------------------------------------\n";
for ($each in $succeed)
print ("// Succeed: " + $each + "\n");
print "-------------------------------------------------\n";
for ($each in $failed)
print ("// Failed: " + $each + "\n");
print "-------------------------------------------------\n";
print ("Succeed: " + size($succeed) + " Failed: " + size($failed) + "\n");
}
// end of script