-
Notifications
You must be signed in to change notification settings - Fork 0
/
tnrClusterComponent.mel
63 lines (52 loc) · 2.34 KB
/
tnrClusterComponent.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
/*
tnrClusterComponent.mel
clusterComponent
*/
/////////////////////////////
// tnrClusterComponent.mel //
//////////////////////////////////////////////////////////
// //
// takes a selection of components of various types, //
// clusters them and attaches the clusters to locators. //
// The locators are then grouped. //
// //
// usage: //
// have an active selection of components //
// source "TR_clusterComponent.mel" //
// //
// //
// Any probs give me a shout //
// TIM //
// tnr@dneg.com //
// //
//////////////////////////////////////////////////////////
global proc clusterComponent()
{
//stores number and names of selected copmonents in variables
string $toCluster_selection[]= `ls -fl -sl`;
int $num_toCluster_selection=`size $toCluster_selection`;
//builds a group for the resulting locators to be stored in
string $clusterComponentGroup= `group -em -n clusterComponent_grp`;
//loop that does the actual work
int $i;
for ($i=0; $i<= ($num_toCluster_selection-1); $i++)
{
//determine world space position for selected component
float $positionInWorldSpace[2]= `xform -worldSpace -q -translation ($toCluster_selection[$i])`;
//select component and build cluster
select -r $toCluster_selection[$i];
cluster -n "toCluster1";
//build cluster at component world space position and center pivot
spaceLocator -n ("toCluster"+($i+1)+"_loc") -p $positionInWorldSpace[0] $positionInWorldSpace[1] $positionInWorldSpace[2];
xform -cp ("toCluster"+($i+1)+"_loc");
//parent cluster to its locator
parent ("toCluster"+($i+1)+"Handle") ("toCluster"+($i+1)+"_loc");
//hide cluster
setAttr ("toCluster"+($i+1)+"Handle.visibility") 0;
//locator with cluster into group
parent ("toCluster"+($i+1)+"_loc") $clusterComponentGroup;
}
//center the pivot of the group and select it
xform -cp $clusterComponentGroup;
select -r $clusterComponentGroup;
}