-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrefpair.mel
More file actions
118 lines (108 loc) · 3 KB
/
refpair.mel
File metadata and controls
118 lines (108 loc) · 3 KB
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
//v0.1b -fix- doRefPair(); bad if statment on doadd=0
// -ren- findref > doRefPair
//v0.1a
global proc string[] refpair(string $mode1, string $mode2){
// tries to find reference pairs if simple name(s) are selected
// or home goems if reference(s) are selected
int $dosel;
int $doadd;
for ($mode in {$mode1, $mode2}){
switch($mode){
case "-sel":
$dosel = 1;
break;
case "-add":
$doadd = 1;
break;
default:
break;
}
}
string $lssl[] = `ls -sl`;
string $msg = "\nPairs forund:";
string $items[] = doRefPair($lssl, $doadd);
if (!size($items))
$msg = "\nNoting is found... -_-'";
print {$msg};
if (size($items)){
print $items;
if ($dosel){
print {"..Selecting"};
select $items;
}
}
return $items;
}
global proc string[] doRefPair(string $lssl[], int $doadd){
/* usage: select local or referenced geometry(transform)
// args:
// - $doadd (int), 1 - get both original and found items
// return: list, reference and its local twin
*/
$chk_cnt = $doadd ? 2 : 1;
string $items[] = stringArrayRemoveDuplicates(
findRefPairs($lssl, $doadd));
if (size($items) < $chk_cnt){
$items = stringArrayRemoveDuplicates(
findPairsFromRef($lssl, $doadd));
if (size($items) < $chk_cnt){
return {};
}
}
return $items;
}
global proc string[] zipItems(string $zipA[], string $zipB[]){
$szA = size($zipA);
$szB = size($zipB);
if ($szA != $szB){
print {" ! Not Equal"};
return {};
}
string $items[];
int $i;
for ($i=0, $j=0; $i<$szA; $i++){
$items[$j++] = $zipA[$i];
$items[$j++] = $zipB[$i];
}
return $items;
}
global proc string[] findRefPairs(string $lssl[], int $add){
// returns only pairs, if pair not found source item is removed
if (!size($lssl))
$lssl = `ls -sl`;
string $items[];
int $i;
for ($sel in $lssl){
$bn = `match "[^|]+$" $sel`;
$ls_ref = `ls ("*:" + $bn)`;
if (size($ls_ref)){
$items[$i++] = $ls_ref[0];
if ($add)
$items[$i++] = $sel;
// $items[$i++] = $bn;
}
}
return $items;
}
global proc string[] findPairsFromRef(string $lssl[], int $add){
// args:
// $add - returns paired list (0, 1), (2, 3)
// returns only pairs, if pair not found source item is removed
if (!size($lssl))
$lssl = `ls -sl`;
string $items[];
// string $pairsA[];
// string $pairsB[];
int $i;
for ($sel in $lssl){
$strip_ns = `match "[^:]+$" $sel`;
$bn = `match "[^|]+$" $strip_ns`;
if (`objExists $bn`){
// $pairsA[$i] = $sel;
if ($add)
$items[$i++] = $sel;
$items[$i++] = $bn;
}
}
return $items;
}