forked from lookbothways/vfxTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
randomiseSelGUI
169 lines (150 loc) · 7.07 KB
/
randomiseSelGUI
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
import random
import maya.cmds as cmds
import maya.mel
"""
import randomiseSelGUI
reload(randomiseSelGUI)
randomiseSelGUI.randomiseThings()
"""
def zeroAxes():
for each in selected:
cmds.setAttr(each+'.rotate', 0, 0, 0, type="double3")
cmds.setAttr(each+'.translate', 0, 0, 0, type="double3")
cmds.setAttr(each+'.scale', 0, 0, 0, type="double3")
def randomiseThings():
value = float(cmds.textFieldGrp(textFieldGrpVar, q=1, text=1))
print "Randomising up to "+str(value)+" degrees"
#For rotation
if instruction == "rx":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.rotateX')
y = cmds.getAttr(each+'.rotateY')
z = cmds.getAttr(each+'.rotateZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.rotate', x+randRotate, y, z, type="double3")
else:
print "Selected is not a transform, ignoring."
if instruction == "ry":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.rotateX')
y = cmds.getAttr(each+'.rotateY')
z = cmds.getAttr(each+'.rotateZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.rotate', x, y+randRotate, z, type="double3")
else:
print "Selected is not a transform, ignoring."
if instruction == "rz":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.rotateX')
y = cmds.getAttr(each+'.rotateY')
z = cmds.getAttr(each+'.rotateZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.rotate', x, y, z+randRotate, type="double3")
else:
print "Selected is not a transform, ignoring."
#For translation
if instruction == "tx":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.translateX')
y = cmds.getAttr(each+'.translateY')
z = cmds.getAttr(each+'.translateZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.translate', x+randRotate, y, z, type="double3")
else:
print "Selected is not a transform, ignoring."
if instruction == "ty":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.translateX')
y = cmds.getAttr(each+'.translateY')
z = cmds.getAttr(each+'.translateZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.translate', x, y+randRotate, z, type="double3")
else:
print "Selected is not a transform, ignoring."
if instruction == "tz":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.translateX')
y = cmds.getAttr(each+'.translateY')
z = cmds.getAttr(each+'.translateZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.translate', x, y, z+randRotate, type="double3")
else:
print "Selected is not a transform, ignoring."
#For scale
if instruction == "sx":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.scaleX')
y = cmds.getAttr(each+'.scaleY')
z = cmds.getAttr(each+'.scaleZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.scale', x+randRotate, y, z, type="double3")
else:
print "Selected is not a transform, ignoring."
if instruction == "sy":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.scaleX')
y = cmds.getAttr(each+'.scaleY')
z = cmds.getAttr(each+'.scaleZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.scale', x, y+randRotate, z, type="double3")
else:
print "Selected is not a transform, ignoring."
if instruction == "sz":
for each in selected:
if cmds.objectType( each, isType='transform') == True:
x = cmds.getAttr(each+'.scaleX')
y = cmds.getAttr(each+'.scaleY')
z = cmds.getAttr(each+'.scaleZ')
rand = random.random()
randRotate = ((rand*2)-1)*value
cmds.setAttr(each+'.scale', x, y, z+randRotate, type="double3")
else:
print "Selected is not a transform, ignoring."
text = 0
instruction = ""
value = 0.0
rx = "rx"
ry = "ry"
rz = "rz"
tx = "tx"
ty = "ty"
tz = "tz"
sx = "sx"
sy = "sy"
sz = "sz"
selected = cmds.ls(sl=True)
# Make a new window
randomiser = cmds.window( title="Randomise selected", iconName='Short Name', widthHeight=(400, 275) )
cmds.columnLayout( adjustableColumn=True )
textFieldGrpVar = cmds.textFieldGrp( label='Random degrees max :', text=10 )
cmds.button( label='X rotation', command=('instruction = rx;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Y rotation', command=('instruction = ry;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Z rotation', command=('instruction = rz;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='X translate', command=('instruction = tx;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Y translate', command=('instruction = ty;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Z translate', command=('instruction = tz;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='X scale', command=('instruction = sx;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Y scale', command=('instruction = sy;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Z scale', command=('instruction = sz;selected = cmds.ls(sl=True);randomiseThings()') )
cmds.button( label='Zero all axes', command=('selected = cmds.ls(sl=True);zeroAxes()') )
cmds.button( label='Close', command=('cmds.deleteUI(\"' + randomiser + '\", window=True);') )
cmds.setParent( '..' )
cmds.showWindow( randomiser )
# This is a workaround to get MEL global variable value in Python
gMainWindow = maya.mel.eval('$tmpVar=$gMainWindow')