質問編集履歴

2

スクリプトの記述

2021/10/07 14:37

投稿

cosuperion
cosuperion

スコア0

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,8 @@
18
18
 
19
19
 
20
20
 
21
+ ```ここに言語を入力
22
+
21
23
  # -*- coding: utf-8 -*-
22
24
 
23
25
  import maya.cmds as cmds
@@ -387,3 +389,7 @@
387
389
  if __name__ == '__main__':
388
390
 
389
391
  mainWindow()
392
+
393
+
394
+
395
+ ```

1

スクリプトの記述

2021/10/07 14:37

投稿

cosuperion
cosuperion

スコア0

test CHANGED
File without changes
test CHANGED
@@ -11,3 +11,379 @@
11
11
  お願いします。
12
12
 
13
13
  それともスクリプトが指定するオブジェクトが存在しないというエラーでしょうか。
14
+
15
+
16
+
17
+ 以下がスクリプトです。
18
+
19
+
20
+
21
+ # -*- coding: utf-8 -*-
22
+
23
+ import maya.cmds as cmds
24
+
25
+ from maya.common.ui import LayoutManager
26
+
27
+
28
+
29
+ def bToS(checked):
30
+
31
+ if checked:
32
+
33
+ return -1.0
34
+
35
+ else:
36
+
37
+ return 1.0
38
+
39
+ def reverse():
40
+
41
+ checkTx = cmds.checkBox('checkTx', q=True, value=True)
42
+
43
+ checkTy = cmds.checkBox('checkTy', q=True, value=True)
44
+
45
+ checkTz = cmds.checkBox('checkTz', q=True, value=True)
46
+
47
+ checkRx = cmds.checkBox('checkRx', q=True, value=True)
48
+
49
+ checkRy = cmds.checkBox('checkRy', q=True, value=True)
50
+
51
+ checkRz = cmds.checkBox('checkRz', q=True, value=True)
52
+
53
+ checkSx = cmds.checkBox('checkSx', q=True, value=True)
54
+
55
+ checkSy = cmds.checkBox('checkSy', q=True, value=True)
56
+
57
+ checkSz = cmds.checkBox('checkSz', q=True, value=True)
58
+
59
+
60
+
61
+ selected = cmds.ls(sl=True,long=True) or []
62
+
63
+
64
+
65
+ # a loop which do something each objects
66
+
67
+ for eachSel in selected:
68
+
69
+ eachSelT = cmds.getAttr(eachSel + '.translate')[0]
70
+
71
+ eachSelR = cmds.getAttr(eachSel + '.rotate')[0]
72
+
73
+ eachSelS = cmds.getAttr(eachSel + '.scale')[0]
74
+
75
+ isLockedTx = cmds.getAttr(eachSel + '.tx', lock=True)
76
+
77
+ isLockedTy = cmds.getAttr(eachSel + '.ty', lock=True)
78
+
79
+ isLockedTz = cmds.getAttr(eachSel + '.tz', lock=True)
80
+
81
+ isLockedRx = cmds.getAttr(eachSel + '.rx', lock=True)
82
+
83
+ isLockedRy = cmds.getAttr(eachSel + '.ry', lock=True)
84
+
85
+ isLockedRz = cmds.getAttr(eachSel + '.rz', lock=True)
86
+
87
+ isLockedSx = cmds.getAttr(eachSel + '.sx', lock=True)
88
+
89
+ isLockedSy = cmds.getAttr(eachSel + '.sy', lock=True)
90
+
91
+ isLockedSz = cmds.getAttr(eachSel + '.sz', lock=True)
92
+
93
+
94
+
95
+ print eachSelT, eachSelR, eachSelS
96
+
97
+ try:
98
+
99
+ if 1:
100
+
101
+ if not isLockedTx:
102
+
103
+ cmds.setAttr(eachSel + '.tx', bToS(checkTx)*eachSelT[0])
104
+
105
+ if not isLockedTy:
106
+
107
+ cmds.setAttr(eachSel + '.ty', bToS(checkTy)*eachSelT[1])
108
+
109
+ if not isLockedTz:
110
+
111
+ cmds.setAttr(eachSel + '.tz', bToS(checkTz)*eachSelT[2])
112
+
113
+ if 1:
114
+
115
+ if not isLockedRx:
116
+
117
+ cmds.setAttr(eachSel + '.rx', bToS(checkRx)*eachSelR[0])
118
+
119
+ if not isLockedRy:
120
+
121
+ cmds.setAttr(eachSel + '.ry', bToS(checkRy)*eachSelR[1])
122
+
123
+ if not isLockedRz:
124
+
125
+ cmds.setAttr(eachSel + '.rz', bToS(checkRz)*eachSelR[2])
126
+
127
+ if 1:
128
+
129
+ if not isLockedSx:
130
+
131
+ cmds.setAttr(eachSel + '.rx', bToS(checkSx)*eachSelS[0])
132
+
133
+ if not isLockedSy:
134
+
135
+ cmds.setAttr(eachSel + '.ry', bToS(checkSy)*eachSelS[1])
136
+
137
+ if not isLockedSz:
138
+
139
+ cmds.setAttr(eachSel + '.rz', bToS(checkSz)*eachSelS[2])
140
+
141
+ except:
142
+
143
+ print "locked attributes didn't change"
144
+
145
+ def mirrorPose():
146
+
147
+ head = 'rig_Head'
148
+
149
+ chest = 'rig_Spine1'
150
+
151
+ waist = 'rig_Spine'
152
+
153
+ shoulderL = 'rig_LeftShoulder'
154
+
155
+ shoulderR = 'rig_RightShoulder'
156
+
157
+ handL = 'rig_LeftHand'
158
+
159
+ handR = 'rig_RightHand'
160
+
161
+ elbowL = 'rig_LeftArmUpv'
162
+
163
+ elbowR = 'rig_RightArmUpv'
164
+
165
+ root = 'rig_COG'
166
+
167
+ hip = 'rig_Hips'
168
+
169
+ kneeL = 'rig_LeftLegUpv'
170
+
171
+ kneeR = 'rig_RightLegUpv'
172
+
173
+ footL = 'rig_LeftFoot'
174
+
175
+ footR = 'rig_RightFoot'
176
+
177
+ toeL = 'rig_LeftToeBase'
178
+
179
+ toeR = 'rig_RightToeBase'
180
+
181
+
182
+
183
+ # temps of hands
184
+
185
+ tempHandL_T = cmds.getAttr(handL + '.translate')[0]
186
+
187
+ tempHandL_R = cmds.getAttr(handL + '.rotate')[0]
188
+
189
+ tempHandR_T = cmds.getAttr(handR + '.translate')[0]
190
+
191
+ tempHandR_R = cmds.getAttr(handR + '.rotate')[0]
192
+
193
+ # temps of elbows
194
+
195
+ tempElbowL_T = cmds.getAttr(elbowL + '.translate')[0]
196
+
197
+ tempElbowR_T = cmds.getAttr(elbowR + '.translate')[0]
198
+
199
+ # temps of shoulders
200
+
201
+ tempShoulderL_R = cmds.getAttr(shoulderL + '.rotate')[0]
202
+
203
+ tempShoulderR_R = cmds.getAttr(shoulderR + '.rotate')[0]
204
+
205
+ # temps of knees
206
+
207
+ tempKneeL_T = cmds.getAttr(kneeL + '.translate')[0]
208
+
209
+ tempKneeR_T = cmds.getAttr(kneeR + '.translate')[0]
210
+
211
+ # temps of foots
212
+
213
+ tempFootL_T = cmds.getAttr(footL + '.translate')[0]
214
+
215
+ tempFootL_R = cmds.getAttr(footL + '.rotate')[0]
216
+
217
+ tempFootR_T = cmds.getAttr(footR + '.translate')[0]
218
+
219
+ tempFootR_R = cmds.getAttr(footR + '.rotate')[0]
220
+
221
+ # temps of toes
222
+
223
+ tempToeL_R = cmds.getAttr(toeL + '.rotate')[0]
224
+
225
+ tempToeR_R = cmds.getAttr(toeR + '.rotate')[0]
226
+
227
+
228
+
229
+ selected = cmds.ls(sl=True) or []
230
+
231
+
232
+
233
+
234
+
235
+ for eachObj in selected:
236
+
237
+ tempTx = cmds.getAttr(eachObj + '.tx')
238
+
239
+ tempTy = cmds.getAttr(eachObj + '.ty')
240
+
241
+ tempTz = cmds.getAttr(eachObj + '.tz')
242
+
243
+ tempRx = cmds.getAttr(eachObj + '.rx')
244
+
245
+ tempRy = cmds.getAttr(eachObj + '.ry')
246
+
247
+ tempRz = cmds.getAttr(eachObj + '.rz')
248
+
249
+
250
+
251
+ if eachObj == head or eachObj == chest or eachObj == waist or eachObj == hip:
252
+
253
+ cmds.setAttr(eachObj + '.ry', -tempRy)
254
+
255
+ cmds.setAttr(eachObj + '.rz', -tempRz)
256
+
257
+ elif eachObj == root:
258
+
259
+ cmds.setAttr(eachObj + '.tx', -tempTx) # maybe
260
+
261
+ cmds.setAttr(eachObj + '.ry', -tempRy)
262
+
263
+ cmds.setAttr(eachObj + '.rz', -tempRz)
264
+
265
+
266
+
267
+ elif eachObj == handL:
268
+
269
+ cmds.setAttr(eachObj + '.translate', -tempHandR_T[0], tempHandR_T[1], tempHandR_T[2])
270
+
271
+ cmds.setAttr(eachObj + '.rotate', tempHandR_R[0], -tempHandR_R[1], -tempHandR_R[2])
272
+
273
+ elif eachObj == handR:
274
+
275
+ cmds.setAttr(eachObj + '.translate', -tempHandL_T[0], tempHandL_T[1], tempHandL_T[2])
276
+
277
+ cmds.setAttr(eachObj + '.rotate', tempHandL_R[0], -tempHandL_R[1], -tempHandL_R[2])
278
+
279
+ elif eachObj == elbowL:
280
+
281
+ cmds.setAttr(eachObj + '.translate', -tempElbowR_T[0], tempElbowR_T[1], -tempElbowR_T[2])
282
+
283
+ elif eachObj == elbowR:
284
+
285
+ cmds.setAttr(eachObj + '.translate', -tempElbowL_T[0], tempElbowL_T[1], -tempElbowL_T[2])
286
+
287
+ elif eachObj == shoulderL:
288
+
289
+ cmds.setAttr(eachObj + '.rotate', tempShoulderR_R[0], -tempShoulderR_R[1], -tempShoulderR_R[2])
290
+
291
+ elif eachObj == shoulderR:
292
+
293
+ cmds.setAttr(eachObj + '.rotate', tempShoulderL_R[0], -tempShoulderL_R[1], -tempShoulderL_R[2])
294
+
295
+ elif eachObj == kneeL:
296
+
297
+ cmds.setAttr(eachObj + '.translate', -tempKneeR_T[0], tempKneeR_T[1], tempKneeR_T[2])
298
+
299
+ elif eachObj == kneeR:
300
+
301
+ cmds.setAttr(eachObj + '.translate', -tempKneeL_T[0], tempKneeL_T[1], tempKneeL_T[2])
302
+
303
+ elif eachObj == footL:
304
+
305
+ cmds.setAttr(eachObj + '.translate', -tempFootR_T[0], tempFootR_T[1], tempFootR_T[2])
306
+
307
+ cmds.setAttr(eachObj + '.rotate', tempFootR_R[0], -tempFootR_R[1], -tempFootR_R[2])
308
+
309
+ elif eachObj == footR:
310
+
311
+ cmds.setAttr(eachObj + '.translate', -tempFootL_T[0], tempFootL_T[1], tempFootL_T[2])
312
+
313
+ cmds.setAttr(eachObj + '.rotate', tempFootL_R[0], -tempFootL_R[1], -tempFootL_R[2])
314
+
315
+ elif eachObj == toeL:
316
+
317
+ cmds.setAttr(eachObj + '.rotate', tempToeR_R[0], tempToeR_R[1], -tempToeR_R[2])
318
+
319
+ elif eachObj == toeR:
320
+
321
+ cmds.setAttr(eachObj + '.rotate', tempToeL_R[0], tempToeL_R[1], -tempToeL_R[2])
322
+
323
+
324
+
325
+ def mainWindow():
326
+
327
+ if cmds.window('ReverserWindow', ex=1):
328
+
329
+ cmds.deleteUI('ReverserWindow')
330
+
331
+ windowName = cmds.window('ReverserWindow',title='Fukuden Mirror v0.01')
332
+
333
+ tabTest = cmds.tabLayout(scrollable=False, innerMarginHeight=5, innerMarginWidth=1)
334
+
335
+
336
+
337
+ with LayoutManager(cmds.columnLayout(adj=True, rowSpacing=10)) as tabTestColumn2:
338
+
339
+ cmds.button(label="(^o MirrorPose o^)", command='FukudenMirror.mirrorPose()')
340
+
341
+ cmds.tabLayout(tabTest, edit=1, tabLabel=(tabTestColumn2, "MirrorPose"))
342
+
343
+
344
+
345
+ with LayoutManager(cmds.columnLayout(adj=True, rowSpacing=10)) as tabTestColumn:
346
+
347
+ with LayoutManager(cmds.rowLayout(numberOfColumns=4, columnAttach4=('right', 'left', 'left', 'left'), columnWidth4=(50, 50, 50, 50))):
348
+
349
+ cmds.text(label="Translate")
350
+
351
+ checkTx = cmds.checkBox('checkTx', label="X")
352
+
353
+ checkTy = cmds.checkBox('checkTy',label="Y")
354
+
355
+ checkTz = cmds.checkBox('checkTz',label="Z")
356
+
357
+ with LayoutManager(cmds.rowLayout(numberOfColumns=4, columnAttach4=('right', 'left', 'left', 'left'), columnWidth4=(50, 50, 50, 50))):
358
+
359
+ cmds.text(label="Rotate")
360
+
361
+ cmds.checkBox('checkRx', label="X")
362
+
363
+ cmds.checkBox('checkRy',label="Y")
364
+
365
+ cmds.checkBox('checkRz',label="Z")
366
+
367
+ with LayoutManager(cmds.rowLayout(numberOfColumns=4, columnAttach4=('right', 'left', 'left', 'left'), columnWidth4=(50, 50, 50, 50))):
368
+
369
+ cmds.text(label="Scale")
370
+
371
+ cmds.checkBox('checkSx', label="X")
372
+
373
+ cmds.checkBox('checkSy',label="Y")
374
+
375
+ cmds.checkBox('checkSz',label="Z")
376
+
377
+ cmds.button(label="(-o-)Reverse(_o_)", command='FukudenMirror.reverse()')
378
+
379
+ cmds.tabLayout(tabTest, edit=2, tabLabel=(tabTestColumn, "ReversePSR"))
380
+
381
+
382
+
383
+ cmds.showWindow()
384
+
385
+
386
+
387
+ if __name__ == '__main__':
388
+
389
+ mainWindow()