-
Notifications
You must be signed in to change notification settings - Fork 0
/
mr_tempPin_pivotFromSelected.mel
208 lines (163 loc) · 8.72 KB
/
mr_tempPin_pivotFromSelected.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
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
// ------------------------------------------------------------------------------------------------------------------------------------------------
// SCRIPT: tempPin_pivotFromSelected
// VERSION: 0001
//
// CREATORS: Maria Robertson
// -------------------------------------------------------------------
//
// DESCRIPTION:
// Pivot a temp pin / temp pin group created from mr_ scripts from the last selected object.
//
// - Creates an offset group for an existing TEMP_worldspace_locator_grp or solo TEMP_worldspace_locator
// - Zeroes out it's values and maintain rotation axis
// - Then have that group pivoted by the current selected object
//
// If both a solo TEMP_worldspace_locator and a TEMP_worldspace_locator_grp exist, the script will run by
// default with the TEMP_worldspace_locator.
//
// -------------------------------------------------------------------
//
// RUN COMMAND:
// TempPinPivotFromSelected() ;
//
// REQUIREMENTS:
// Must have mr_findDriversOfSelected.mel in order to use the procedure FindDriversOfSelected
//
// Can be used with following scripts:
// - mr_tempPin.mel
// - mr_tempPinIndividual.mel
//
//
// -------------------------------------------------------------------
//
// RESEARCH THAT HELPED:
// For listing relatives - https://forums.cgsociety.org/t/list-all-parents-of-an-object-mel/1806687/2
// For better understanding MEL and strings / arrays - https://forums.cgsociety.org/t/mel-compare-strings/1487805/4
//
// ------------------------------------------------------------------------------------------------------------------------------------------------
global proc TempPinPivotFromSelected() {
// -------------------------------------------------------------------
// 01. INITIALIZE VARIABLES
// -------------------------------------------------------------------
string $tempPin_solo = "TEMP_worldspace_locator" ;
string $tempPin_group = "TEMP_worldspace_locator_grp" ;
string $pivot[0] = `ls -sl` ;
string $pivotOffsetGroup = "TEMP_pivot_offset" ;
// -------------------------------------------------------------------
// 01. IF AN OFFSET GROUP ALREADY EXISTS, KEY THE TARGETS AND DELETE THE GROUP
// -------------------------------------------------------------------
// if an offset group already exists
if (`objExists $pivotOffsetGroup`) {
delete -cn $pivotOffsetGroup ;
string $pivotOffsetGroupChildren[0] = `listRelatives -c $pivotOffsetGroup` ;
// set keys on the child
select $pivotOffsetGroupChildren ;
SetKeyTranslate ;
SetKeyRotate ;
// parent the target to worldspace
parent -w ;
// delete the group
delete $pivotOffsetGroup ;
}
//////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------- //
// //
// FOR A SOLO TEMP LOCATOR //
// //
// -------------------------------------------------------------------- //
//////////////////////////////////////////////////////////////////////////
// if a TEMP_worldspace_locator exists
else if (`objExists $tempPin_solo`) {
// -------------------------------------------------------------------
// 02. CHECK SELECTION
// -------------------------------------------------------------------
// if nothing or more than one object is selected
if (size($pivot) != 1) {
// give an error
// NOTE: make sure -title is unique, otherwise dialog won't trigger
confirmDialog -title "Error A" -message "Select one object to pivot from." ;
}
// or if a TEMP_worldspace_locator is selected as the pivot
else if ($pivot[0] == $tempPin_solo) {
// give an error
confirmDialog -title "Error B" -message "Can't use a Temp Pin as a pivot." ;
}
// or if a TEMP_worldspace_locator_grp is selected as the pivot
else if ($pivot[0] == $tempPin_group) {
// give an error
confirmDialog -title "Error B" -message "Can't use a Temp Pin Group as a pivot." ;
}
// -------------------------------------------------------------------
// 02. CREATE AN OFFSET GROUP TO PIVOT
// -------------------------------------------------------------------
else {
// create an offset group to pivot
string $nullGroup = `group -em -name $pivotOffsetGroup` ;
parentConstraint -w 1 $tempPin_solo $nullGroup ;
// NOTE: have to specifically name the constraint to delete, otherwise the null
// group itself gets deleted too if "delete -cn" or "DeleteConstraints" is used
delete ($nullGroup + "_parentConstraint1") ;
// parent constrain target to offset group
parent $tempPin_solo $nullGroup;
parentConstraint -mo -w 1 $pivot $nullGroup;
select $pivot;
}
}
//////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------- //
// //
// FOR A TEMP LOCATOR GROUP //
// //
// -------------------------------------------------------------------- //
//////////////////////////////////////////////////////////////////////////
// if a TEMP_worldspace_locator exists
else if (`objExists $tempPin_group`) {
// -------------------------------------------------------------------
// 02A. CHECK SELECTION
// -------------------------------------------------------------------
// if nothing or more than one object is selected
if (size($pivot) != 1) {
// give an error
// NOTE: make sure -title is unique, otherwise dialog won't trigger
confirmDialog -title "Error A" -message "Select one object to pivot from." ;
}
// or if a TEMP_worldspace_locator is selected as the pivot
else if ($pivot[0] == $tempPin_solo) {
// give an error
confirmDialog -title "Error B" -message "Can't use a Temp Pin as a pivot." ;
}
// or if a TEMP_worldspace_locator_grp is selected as the pivot
else if ($pivot[0] == $tempPin_group) {
// give an error
confirmDialog -title "Error B" -message "Can't use a Temp Pin Group as a pivot." ;
}
// -------------------------------------------------------------------
// 02B. CREATE OFFSET GROUP TO PIVOT
// -------------------------------------------------------------------
else {
// create offset group to pivot
string $nullGroup = `group -em -name $pivotOffsetGroup` ;
parentConstraint -w 1 $tempPin_group $nullGroup ;
// NOTE - have to specifically name the constraint to delete, otherwise the null
// group itself gets deleted too if "delete -cn" is used
delete ($nullGroup + "_parentConstraint1") ;
// parent constrain target to offset group
parent $tempPin_group $nullGroup;
parentConstraint -mo -w 1 $pivot $nullGroup;
select $pivot;
}
}
//////////////////////////////////////////////////////////////////////////
// -------------------------------------------------------------------- //
// //
// IF NO TEMP PINS EXIST //
// //
// -------------------------------------------------------------------- //
//////////////////////////////////////////////////////////////////////////
// if both of the conditions don't exist
else {
// reminds you to select something //
// make sure -title is unique, otherwise dialog won't trigger
confirmDialog -title "Error C" -message "Create TEMP_worldspace_locators first." ;
}
}