-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathibk.py
450 lines (327 loc) · 14.6 KB
/
ibk.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
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#!python2
MajorVersion = "1"
MinorVersion = "0"
PatchVersion = "0"
PreReleaseVersionType = "m"
PreReleaseVersion = ""
IBK_LICESE = """
MIT License
Copyright (c) 2020 Prana Ronita
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
"""
#---------------------------------------------------------------- ----------------------------------------------------------------#
_author_ = "Prana Ronita"
_portfolio_ = "www.prsfx.net"
_email_ = "[email protected] / [email protected]"
_social_ = "@prsfx"
_github_ = "https://github.com/prsfx/ibk-maya"
_projectname_ = "IBK for Maya "
_version_ = " v" + MajorVersion + "." + MinorVersion + "." + PatchVersion + " " + PreReleaseVersionType
_about_ = "© 2020 | Prana Ronita | @prsfx"
_lastmodified_ = "2020-April-1"
#---------------------------------------------------------------- ----------------------------------------------------------------#
print("OROOO")
"""import modules"""
import os
import ibk
import xml.etree.ElementTree as xml
from config.vendor.LoDb import *
from config.vendor.LoDb import loadUiType
from config.vendor.LoDb import wrapinstance
from cStringIO import StringIO
from maya import mel as mel
from maya import cmds as cmds
from maya import OpenMayaUI as omui
from maya.app.general.mayaMixin import MayaQWidgetDockableMixin
#---------------------------------------------------------------- ----------------------------------------------------------------#
"""decalre and function"""
# primary source path
Source = os.path.dirname(__file__)
# global for selection command
slctn = cmds.ls(sl=True)
# look up for Maya main window
def mayaMainWindow():
main_window_ptr = omui.MQtUtil.mainWindow()
return wrapinstance(long(main_window_ptr), QtWidgets.QWidget)
# check if it's Maya
def isMaya():
try:
import maya.cmds as cmds
cmds.about(batch=True)
return True
except ImportError:
return False
# tweener
def tweenIBK(percentage, slctn=None, attrs=None, selection=True):
if not slctn and not selection:
cmds.warning("No object selection...")
raise ValueError("No object selection...")
if not slctn:
slctn = cmds.ls(sl=True)[0]
if not attrs:
attrs = cmds.listAttr(slctn, keyable=True)
crtm = cmds.currentTime(q=True)
for attr in attrs:
attrFull = "%s.%s" % (slctn, attr)
keyframes = cmds.keyframe(attrFull, q=True, tds=True)
if not keyframes:
continue
previousKeyframes = []
for frame in keyframes:
if frame < crtm:
previousKeyframes.append(frame)
laterKeyframes = [frame for frame in keyframes if frame > crtm]
if not previousKeyframes and not keyframes:
continue
if previousKeyframes:
previousFrame = max(previousKeyframes)
else:
previousFrame = None
nextFrame = min(laterKeyframes) if laterKeyframes else None
if not previousFrame or not nextFrame:
continue
previousValue = cmds.getAttr(attrFull, time=previousFrame)
nextValue = cmds.getAttr(attrFull, time=nextFrame)
difference = nextValue - previousValue
try:
weightedDifference = (float(difference) * float(percentage)) / 100.0
except TypeError:
pass
try:
currentValue = previousValue + weightedDifference
except UnboundLocalError:
pass
try:
cmds.setKeyframe(attrFull, time=crtm, value=currentValue)
except UnboundLocalError:
pass
#---------------------------------------------------------------- ----------------------------------------------------------------#
"""declare windows/widget name"""
Ibk_WindowName = "IBK-tool"
IbkMixin_DockName = "IBK-tools-dock"
#---------------------------------------------------------------- ----------------------------------------------------------------#
"""IBK main class"""
# ibk global form
ibk_form, ibk_base = loadUiType(Source + "/ibk_form.ui")
# ibk main class
class ibkUI(ibk_form, ibk_base):
def __init__(self, parent=None):
super(ibkUI, self).__init__(parent)
# setup ui
self.setupUi(self)
# value slider
self.ibk_horizontalSlider.valueChanged.connect(self.__valueIbkInfoChanged)
# value button
self.ibk_000_pButton.clicked.connect(self.__000tweenButton)
self.ibk_010_pButton.clicked.connect(self.__010tweenButton)
self.ibk_020_pButton.clicked.connect(self.__020tweenButton)
self.ibk_030_pButton.clicked.connect(self.__030tweenButton)
self.ibk_040_pButton.clicked.connect(self.__040tweenButton)
self.ibk_050_pButton.clicked.connect(self.__050tweenButton)
self.ibk_060_pButton.clicked.connect(self.__060tweenButton)
self.ibk_070_pButton.clicked.connect(self.__070tweenButton)
self.ibk_080_pButton.clicked.connect(self.__080tweenButton)
self.ibk_090_pButton.clicked.connect(self.__090tweenButton)
self.ibk_100_pButton.clicked.connect(self.__100tweenButton)
#---------------------------------------------------------------#
# value slider
def __valueIbkInfoChanged(self, *args):
slctn = cmds.ls(sl=True)
CurrentTime = cmds.currentTime(q=True)
ValueChanged = str(self.ibk_horizontalSlider.value())
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
# value button
def __000tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 0
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __010tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 10
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __020tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 20
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __030tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 30
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __040tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 40
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __050tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 50
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __060tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 60
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __070tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 70
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __080tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 80
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __090tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 90
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
def __100tweenButton(self, *args):
slctn = cmds.ls(sl=True)
ValueInput = 100
CurrentTime = cmds.currentTime(q=True)
ValueChanged = self.ibk_horizontalSlider.setValue(ValueInput)
# check how many value will change
print("Slider value changed... " + str(ValueChanged) +"%")
tweenIBK(ValueChanged)
cmds.keyframe(slctn, tds=True, t=(CurrentTime, CurrentTime))
# close
def closeEvent(self, *args):
self.parent().close()
#---------------------------------------------------------------- ----------------------------------------------------------------#
# ibk mixin class
class ibkToolMixinWindowDock(MayaQWidgetDockableMixin, ibk.ibkUI):
# tool name to connect instances
ibkTool_name = Ibk_WindowName
def __init__(self, parent=None):
# try delete instance first
self.deleteInstances()
super(ibkToolMixinWindowDock, self).__init__(parent)
# get maya main window
mayaMainWindow()
# set window title
self.setWindowTitle(Ibk_WindowName)
# set window flags
self.setWindowFlags(QtCore.Qt.Window)
# delete dialog
"""
As with close() ,
deletes the dialog if the WA_DeleteOnClose flag is set.
If the dialog is the application’s main widget, the application terminates.
If the dialog is the last window closed, the lastWindowClosed() signal is emitted.
"""
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
#---------------------------------------------------------------#
# triger delete instances
def dockCloseEventTriggered(self, *args):
self.deleteInstances()
# delete instances inside Maya
def deleteInstances(self, *args):
for obj in mayaMainWindow().children():
if str(type(obj)) == ibkToolMixinWindowDock:
if obj.widget().objectName() == self.__class__.ibkTool_name:
print 'Deleting instance {0}'.format(obj)
mayaMainWindow().removeDockWidget(obj)
obj.setParent(None)
obj.deleteLater()
# delete maya control workspace
def deleteControl(self, control):
if cmds.workspaceControl(control, q=True, exists=True):
cmds.workspaceControl(control, e=True, close=True)
cmds.deleteUI(control, control=True)
# run ibk mixin class
def run(self):
# set object name
self.setObjectName(Ibk_WindowName)
# workspace control name
workspaceControlName = self.objectName() + "WorkspaceControl"
# delete workspace control
self.deleteControl(workspaceControlName)
# set dock/undock parameter here
self.show(dockable=True, area="middle", floating=True)
# workspace area
#cmds.workspaceControl(workspaceControlName, e=True, wp="preferred", w=282, h=60)
cmds.workspaceControl(workspaceControlName, e=True, dtc=["AttributeEditor", "bottom"], wp="preferred", w=282, h=60)
# raise to window
self.raise_()
# dock it by using this if you need it
self.setDockableParameters(width=282, height=60)
#---------------------------------------------------------------- ----------------------------------------------------------------#
"""Launch setup"""
# Maya mixin setup
def launch_ibk():
ibkMixinWindow = ibkToolMixinWindowDock()
ibkMixinWindow.run()
return ibkMixinWindow
# main launcher setup
def main(*args, **kwargs):
if ibk.isMaya():
libk = launch_ibk()
return libk
if __name__ == "__main__":
with ibk.app():
ibk.main()