-
Notifications
You must be signed in to change notification settings - Fork 0
/
ckFidget.py
290 lines (235 loc) · 10.1 KB
/
ckFidget.py
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
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
"""
ckFidget.py
written by: Carl Keifer
This tool allows users to modify sets of data while tracking revisions. it can
operate on a set of data channels by increment or percent. fidget data is stored
in a group node so that it persists from save to save.
CK - currently the tool only works for mel based windows.
it would be great to do the same thing with QT.
I'm going to add multiple versions of save.
"""
import maya.OpenMayaUI as apiUI
import sip
import sys
import pymel.all as pm
# I should create an initialize fidget function that can load persistent data from
# a previous fidget session.
# this is the amount by default that will be affecting the attributes
pm.melGlobals.initVar( 'float','gckFidgetBump')
pm.melGlobals['gckFidgetBump'] = 0.1
def ckGetList( fdgAttr ):
"""
ckGetList( fdgAttr )
description: returns list from the fidget data
assumes list always ends with ;
inputs:
fdgAttr: the object.attribute that we will be looking for data in
outputs: returns list of data that lives in fdgAttr
"""
ckList = pm.getAttr(fdgAttr)
ckList = ckList.split(";")
ckList.pop()
return ckList
def ckAddToList(fdgAttr, fdgVal):
"""
ckAddToList(fdgAttr, fdgVal):
description: adds value in fdgVal to the list located at fdgAttr
assumes the list always ends with ;
inputs:
fdgAttr: the object.attribute that we will be looking for data in
fdgVal: the data we will be adding to the list
outputs: None
"""
ckAttr = pm.getAttr(fdgAttr)
ckAttr = ckAttr + str(fdgVal) + ";"
pm.setAttr(fdgAttr, ckAttr )
def ckFidgetInit():
"""
ckFidgetInit()
description: this function should initialize ckFidget
it should check for existing persistent data
and create a new node if none exists
then it creates the interface
inputs: None
outputs: initializes ckFidget
"""
try:
print "checking for persistent fidget data"
pm.select("ckFidget_GRP")
isFidget = pm.getAttr("ckFidget_GRP.ckIsFidget")
if isFidget == True:
print "Data Found!"
pm.setAttr("ckFidget_GRP.bumpBy", False)
except:
print "data not found initializing new ckFidget instance"
pm.group(empty=True, name="ckFidget_GRP")
pm.addAttr( longName="ckIsFidget", attributeType='bool', keyable=False )
pm.setAttr("ckFidget_GRP.ckIsFidget", True)
pm.addAttr( longName="bumpBy", attributeType='bool', keyable=False )
pm.setAttr("ckFidget_GRP.bumpBy", False)
pm.addAttr( longName="ckFidgetBump", attributeType='float', keyable=False, defaultValue=0.1 )
pm.addAttr( longName="numSaves", attributeType="short", keyable=False, defaultValue=0 )
print "here is where I should ask about starting a new fidget"
# should pop up a dialog and ask the name of the new fidget
pm.addAttr( longName="ckFidgetList", dataType='string', keyable=False )
pm.addAttr( longName="ckFidgetSav", dataType='string', keyable=False )
pm.setAttr( "ckFidget_GRP.ckFidgetList","" )
pm.setAttr( "ckFidget_GRP.ckFidgetSav","" )
pm.select( clear = True )
ckFidgetWin()
def ckAddFidget():
"""
ckAddFidget( )
description: this function collects the selected attribute and adds it
to the list of data that fidget will work with
inputs: None
outputs: None
CK - this would be a great place to add data to a persistent node in the
maya file(working)
"""
# fist we are collecting the selected attribute
atribSel = pm.mel.eval('selectedChannelBoxAttributes();')
# then we get the object said attribute belongs to
slectItm = pm.ls( selection = True )
# the two are added together so we can work with the information
# inside the maya context
newAttr = slectItm.pop() + '.' + atribSel.pop()
# this is a test to ensure that we are in fact getting some kind of data from
# the attribute
newVal = pm.getAttr( newAttr )
print newVal
pm.select( clear = True )
# given that has worked we will add the data to the lists
ckAddToList( "ckFidget_GRP.ckFidgetList", newAttr)
ckAddToList( "ckFidget_GRP.ckFidgetSav", newVal)
pm.group(name = str(newAttr+"_SAV0" ))
pm.addAttr( longName="fdgSave", dataType="string", keyable=False)
newAttr = newAttr.split(".")
pm.setAttr( str(newAttr[0]+"_"+newAttr[1]+"_SAV0.fdgSave"), str(newVal))
pm.select( "ckFidget_GRP")
pm.parent( str(newAttr[0]+"_"+newAttr[1]+"_SAV0") )
pm.select( clear = True )
pm.select(newAttr[0])
# now issue the call to rebuild the interface
ckFidgetWin()
def ckFidgetBumpAll(bumpDir):
"""
ckFidgetBumpAll(bumpDir)
description: evaluates list of fidgets
inputs:
bumpDir: determines if the operation is add or subtract
outputs: None
"""
print "bumping all fidgets " + str(bumpDir)
ckList = ckGetList("ckFidget_GRP.ckFidgetList")
for fdg in ckList:
ckFidgetBump(fdg, bumpDir)
def ckFidgetBump( fdgAttr, bumpDir):
"""
ckFidgetBump( fdgAttr, bumpDir )
description: evaluates fidget for given attribute, adds or subtracts
by percent or increment
inputs:
fdgAttr: the object.attribute that we will be looking for data in
bumpDir: determines if the operation is add or subtract
outputs: None
"""
print "bumping " + str(bumpDir)+ " " + str(fdgAttr)
bumpBy = pm.getAttr("ckFidget_GRP.bumpBy")
fdgVal = pm.getAttr( fdgAttr )
bumpAmt = pm.melGlobals.get('gckFidgetBump')
# bumping by percentage, figure out percentage and adjust fdgVal attribute
if(bumpBy == True):
print " by percent"
bumpAmt = bumpAmt / 100
bumpAmt = fdgVal * bumpAmt
if bumpDir == "Up":
fdgVal = fdgVal + bumpAmt
else:
fdgVal = fdgVal - bumpAmt
# store adjustment
pm.setAttr( fdgAttr, fdgVal)
def ckSavRstZerAll( fdgOps ):
"""
ckSavRstZerAll( fdgAttr, fdgOps )
description: saves, restores, or zeros all attributes listed in fidget set.
inputs:
fdgOps: the operation to complete, save or restore
outputs: None
"""
print fdgOps + "ing all fidgets in dataset"
ckList = ckGetList("ckFidget_GRP.ckFidgetList")
for fdg in ckList:
if fdgOps == "save":
ckSavRst(fdg, fdgOps)
elif fdgOps == "restore":
ckSavRst(fdg, fdgOps)
else:
pm.setAttr(fdg, 0)
def ckSavRst(fdgAttr, fdgOps ):
"""
ckSavRst()
description: saves or restores values from fidget data
inputs:
fdgAttr: the object.attribute pair we will be working with
fdgOps: the operation to complete, save or restore
outputs: None
"""
print str(fdgOps) + "ing entry for, ", fdgAttr
fdgGrp = fdgAttr.split(".")
if fdgOps == "save":
fdgSav = pm.getAttr(fdgAttr)
pm.setAttr(str("ckFidget_GRP|"+fdgGrp[0]+"_"+fdgGrp[1]+"_SAV0.fdgSave"), str(fdgSav) )
else:
fdgSav = pm.getAttr(str("ckFidget_GRP|"+fdgGrp[0]+"_"+fdgGrp[1]+"_SAV0.fdgSave"))
pm.setAttr(fdgAttr, float(fdgSav))
def ckFidgetWin():
"""
ckFidgetWin()
description: creates interface for ckFidget tool. the list is built dynamically
from the list of active fidgets on load, so the more fidgets you add. the
longer the tool window will become.
inputs:
outputs: the main fidget window.
CK - I should add some menus to this that have basic falloffs
for common tasks, like cloth, sss, or lighting.
"""
if pm.mel.eval('window -ex "fidgetMainWin" ;'):
pm.mel.eval('deleteUI "fidgetMainWin";' )
fidgetWin = pm.mel.eval('window -title "Carl Keifer attribute fidgeter" -width 150 fidgetMainWin;')
pm.columnLayout( adjustableColumn=True )
pm.frameLayout( label = "Build Fidget", borderStyle='in', collapsable=True )
pm.rowLayout( numberOfColumns=5, columnWidth=(75,75) )
pm.button( label = 'Add Fidget', command = 'ckAddFidget()' )
pm.button( label = 'refresh UI', command = 'ckFidget()' )
pm.button( label = 'Save All', command = 'ckSavRstZerAll( "save" )')
pm.button( label = 'Zero All', command = 'ckSavRstZerAll( "zero" )')
pm.button( label = 'Restore All', command = 'ckSavRstZerAll( "restore" )')
pm.setParent( '..' )
pm.setParent( '..' )
pm.frameLayout( label = "Master Fidget", borderStyle='in', collapsable=True )
pm.rowLayout( numberOfColumns=6, columnWidth=(75,75) )
pm.mel.eval( 'floatField -value $gckFidgetBump -min 0 -changeCommand "$gckFidgetBump = `floatField -q -v masterBump`" masterBump;' )
pm.button( label = '<', command = 'ckFidgetBumpAll("Down")')
pm.button( label = '>', command = 'ckFidgetBumpAll("Up")')
pm.radioButtonGrp( label='Bump by:', labelArray2=['0.0', '%'], numberOfRadioButtons=2, sl=1, on1= 'pm.setAttr("ckFidget_GRP.bumpBy", False)', on2= 'pm.setAttr("ckFidget_GRP.bumpBy", True)')
pm.setParent( '..' )
pm.setParent( '..' )
pm.frameLayout( label = "Fidget Attributes", borderStyle='in', collapsable=True )
e = 0
# this iterates the list of fidgets we have
ckList = ckGetList("ckFidget_GRP.ckFidgetList")
for i in ckList:
print "i, ",i
pm.rowLayout( numberOfColumns=6, columnWidth=(75,75) )
pm.attrFieldSliderGrp( l=str(i), min=-10.0, max=10.0, at = i )
pm.button( label = '<', command = 'ckFidgetBump(\"'+i+'\", "Down")' )
pm.button( label = '>', command = 'ckFidgetBump( \"'+i+'\","Up")' )
pm.button( label = 'save', command = 'ckSavRst( \"'+i+'\", "save")')
pm.button( label = 'zero', command = 'pm.setAttr( \"'+i+'\", 0)' )
pm.button( label = 'restore', command = 'ckSavRst( \"'+i+'\", "restore")')
pm.setParent( '..' )
pm.setParent( '..' )
pm.setParent( '..' )
pm.showWindow(fidgetWin)
# I should now connect the master fidget value to the fidget group