-
Notifications
You must be signed in to change notification settings - Fork 2
/
ita_PlayView.py
423 lines (332 loc) · 15.8 KB
/
ita_PlayView.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
"""
PlayView: Save a viewport for single-view playback mode.
This script will benefit you if your playback mode is set to "active"
instead of "all." Otherwise it will play forward as normal. Use the given
button grid to select a viewport to play through. Set it as default to save
it for future playback. Set this script to a hotkey for easy reuse.
Help: Open a help window with this information in it.
Cancel: Close PlayView without setting defaults or playback.
Make Default: Save selected viewport to prevent future prompts.
Select a viewport with the provided buttons. One window will pop up for each
window with a viewport in it.
import ita_PlayView
#reload(ita_PlayView) # To reset default
#ita_PlayView.destroy_window() # To destroy all PlayView windows
ita_PlayView.init()
(c) Jeffrey "italic" Hoover
italic DOT rendezvous AT gmail DOT com
30 October 2016
Licensed under the Apache 2.0 license.
This script can be used for non-commercial
and commercial projects free of charge.
For more information, visit:
https://www.apache.org/licenses/LICENSE-2.0
"""
import logging
import maya.cmds as cmds
import maya.mel as mel
from functools import partial
log = logging.getLogger(__name__)
log.setLevel(logging.INFO)
windowID = 'PlayView'
helpID = 'PlayViewHelp'
custom_viewport = "" # Saves panel name for future playback
def play_button(*args):
"""Play functionality."""
return mel.eval(
"undoInfo -stateWithoutFlush off;"
"playButtonForward;"
"undoInfo -stateWithoutFlush on;"
)
def play_view(view):
"""Play with specified viewport."""
cmds.setFocus(view)
destroy_window()
play_button()
def play_view_caller(make_default, view, *args):
"""
Caller to make use of Default checkbox.
Ultimately call play_view() to play with specific view.
"""
if cmds.checkBox(make_default, q=True, v=True) is True:
global custom_viewport
custom_viewport = view
log.info("Default viewport for playback is now {}.".format(custom_viewport))
play_view(view)
def gui(ctrl, pWindowTitle, winID, TLC, *args):
"""Draw window."""
lconfig = get_layout_config(ctrl)
lconfigarray = get_layout_child_array(ctrl)
log.debug("Layout: {}".format(ctrl))
log.debug("Layout config: {}".format(lconfig))
log.debug("Children: {}".format(lconfigarray))
win_draw = cmds.window(
winID,
title=pWindowTitle,
titleBar=False,
sizeable=False,
resizeToFitChildren=True,
tlc=TLC,
wh=(255, 200)
)
rowcol = cmds.rowColumnLayout(
numberOfColumns=1,
columnWidth=[(1, 250)],
columnOffset=[(1, 'both', 5)]
)
cmds.separator(h=5, style='none')
cmds.text(label='Select a viewport to play from.')
cmds.separator(h=5, style='none')
cmds.rowLayout(
parent=rowcol,
numberOfColumns=3,
columnAttach=[
(1, 'both', 0),
(2, 'both', 5),
(3, 'both', 0)
],
columnWidth=[
(1, 75), # Total == 250 - margins
(2, 90),
(3, 75)
]
)
cmds.button(label='Help', command=help_call)
makeDefault = cmds.checkBox(label='Make Default')
cmds.button(label='Cancel', command=destroy_window)
button_grid(rowcol, lconfigarray, makeDefault, lconfig)
cmds.showWindow()
cmds.window(win_draw, e=True, tlc=TLC, wh=(255, 200))
def button_grid(parent, child_array, make_default, layout_config=None, *args):
"""UI grid based on layout from get_layout_config()."""
RC = cmds.columnLayout(p=parent)
cmds.rowLayout(parent=RC, nc=1)
cmds.separator(h=5, style='none')
if layout_config == "single":
# 1*1, center button
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=135, label="", command=partial(play_view_caller, make_default, child_array[0]))
elif layout_config == "quad":
# 2*2
cmds.rowLayout(parent=RC, nc=2)
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.rowLayout(parent=RC, nc=2)
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[3]))
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[2]))
elif layout_config == "horizontal2":
# 1*2
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[1]))
elif layout_config == "vertical2":
# 2*1
cmds.rowLayout(parent=RC, nc=2)
cmds.button(w=(240 / 2), h=135, label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.button(w=(240 / 2), h=135, label="", command=partial(play_view_caller, make_default, child_array[1]))
elif layout_config == "horizontal3":
# 1*3
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 3), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 3), label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 3), label="", command=partial(play_view_caller, make_default, child_array[2]))
elif layout_config == "vertical3":
# 3*1
cmds.rowLayout(parent=RC, nc=3)
cmds.button(w=(240 / 3), h=135, label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.button(w=(240 / 3), h=135, label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.button(w=(240 / 3), h=135, label="", command=partial(play_view_caller, make_default, child_array[2]))
elif layout_config == "top3":
# 2*1
cmds.rowLayout(parent=RC, nc=2)
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 2), label="", command=child_array[2])
elif layout_config == "left3":
# 2*2
row1 = cmds.rowLayout(p=RC, nc=2)
col1 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=(130 / 2), p=col1, label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.separator(h=5, style='none')
cmds.button(w=(240 / 2), h=(130 / 2), p=col1, label="", command=partial(play_view_caller, make_default, child_array[2]))
col2 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=135, p=col2, label="", command=partial(play_view_caller, make_default, child_array[1]))
elif layout_config == "bottom3":
# 2*1
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.rowLayout(parent=RC, nc=2)
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[2]))
cmds.button(w=(240 / 2), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[1]))
elif layout_config == "right3":
# 2*2
row1 = cmds.rowLayout(p=RC, nc=2)
col1 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=135, p=col1, label="", command=partial(play_view_caller, make_default, child_array[0]))
col2 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=(130 / 2), p=col2, label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.separator(h=5, style='none')
cmds.button(w=(240 / 2), h=(130 / 2), p=col2, label="", command=partial(play_view_caller, make_default, child_array[2]))
elif layout_config == "horizontal4":
# 1*4
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 4), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 4), label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 4), label="", command=partial(play_view_caller, make_default, child_array[2]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 4), label="", command=partial(play_view_caller, make_default, child_array[3]))
elif layout_config == "vertical4":
# 4*1
cmds.rowLayout(parent=RC, nc=4)
cmds.button(w=(240 / 4), h=135, label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.button(w=(240 / 4), h=135, label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.button(w=(240 / 4), h=135, label="", command=partial(play_view_caller, make_default, child_array[2]))
cmds.button(w=(240 / 4), h=135, label="", command=partial(play_view_caller, make_default, child_array[3]))
elif layout_config == "top4":
# 3*2
cmds.rowLayout(parent=RC, nc=3)
cmds.button(w=(240 / 3), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.button(w=(240 / 3), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.button(w=(240 / 3), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[2]))
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[3]))
elif layout_config == "left4":
# 2*3
row1 = cmds.rowLayout(p=RC, nc=2)
col1 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=(135 / 3) - 3, p=col1, label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.separator(h=4, style='none')
cmds.button(w=(240 / 2), h=(135 / 3) - 3, p=col1, label="", command=partial(play_view_caller, make_default, child_array[3]))
cmds.separator(h=4, style='none')
cmds.button(w=(240 / 2), h=(135 / 3) - 3, p=col1, label="", command=partial(play_view_caller, make_default, child_array[2]))
col2 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=135, p=col2, label="", command=partial(play_view_caller, make_default, child_array[1]))
elif layout_config == "bottom4":
# 3*2
cmds.rowLayout(parent=RC, nc=1)
cmds.button(w=240, h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[0]))
cmds.rowLayout(parent=RC, nc=3)
cmds.button(w=(240 / 3), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[3]))
cmds.button(w=(240 / 3), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[2]))
cmds.button(w=(240 / 3), h=(135 / 2), label="", command=partial(play_view_caller, make_default, child_array[1]))
elif layout_config == "right4":
# 2*3
row1 = cmds.rowLayout(p=RC, nc=2)
col1 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=135, p=col1, label="", command=partial(play_view_caller, make_default, child_array[0]))
col2 = cmds.columnLayout(p=row1)
cmds.button(w=(240 / 2), h=(135 / 3) - 3, p=col2, label="", command=partial(play_view_caller, make_default, child_array[1]))
cmds.separator(h=4, style='none')
cmds.button(w=(240 / 2), h=(135 / 3) - 3, p=col2, label="", command=partial(play_view_caller, make_default, child_array[2]))
cmds.separator(h=4, style='none')
cmds.button(w=(240 / 2), h=(135 / 3) - 3, p=col2, label="", command=partial(play_view_caller, make_default, child_array[3]))
cmds.rowLayout(parent=RC, nc=1)
cmds.separator(h=5, style='none')
return RC
def help_call(*args):
"""Open a text window with help information."""
helpText = (
"PlayView: Always play a specific viewport.\n"
"\n"
"Cancel: Close PlayView without setting defaults or playback.\n"
"Make Default: Save selected viewport to prevent future prompts.\n"
"Select a viewport with the provided buttons. One PlayView \n"
"window will pop up for each window with a viewport in it.\n"
"\n"
"(c) Jeffrey 'italic' Hoover\n"
"italic DOT rendezvous AT gmail DOT com\n"
"\n"
"Licensed under the Apache 2.0 license.\n"
"This script can be used for non-commercial\n"
"and commercial projects free of charge.\n"
"For more information, visit:\n"
"https://www.apache.org/licenses/LICENSE-2.0\n"
)
if cmds.window(helpID, exists=True):
cmds.deleteUI(helpID)
cmds.window(
helpID,
title='PlayViewHelp',
widthHeight=[300, 200],
sizeable=True,
resizeToFitChildren=True
)
cmds.columnLayout(width=300)
cmds.scrollField(
wordWrap=True,
text=helpText,
editable=False,
width=300,
height=200,
font='smallPlainLabelFont'
)
cmds.showWindow()
def draw_PlayView(pWindowTitle, *args):
ctrl_set = set()
wInd = 0
WH = (-75, -125) # Window dimensions are 250*150, negated for addition
for panel in cmds.getPanel(vis=True):
try:
ctrl = cmds.modelPanel(panel, q=True, control=True)
ctrl_set.add(get_layout_control(ctrl))
log.debug("Panel: {}".format(ctrl))
log.debug("Control: {}".format(ctrl_set))
except:
pass
for parent in ctrl_set:
for w in get_windows():
if parent.startswith(w):
WC = get_window_center(w)
TLC = [sum(x) for x in zip(WC, WH)]
log.debug("Window center: {}".format(WC))
log.debug("Top-left corner: {}".format(TLC))
gui(parent, pWindowTitle, "{}{}".format(windowID, wInd), TLC)
log.debug("Window: {}{}".format(windowID, wInd))
log.debug("Control: {}".format(parent))
wInd += 1
def get_windows(*args):
"""Get all available windows."""
return cmds.lsUI(windows=True)
def get_window_center(window, *args):
"""Get window's center position."""
WH = [l // 2 for l in cmds.window(window, q=True, wh=True)]
WH.reverse()
TLC = cmds.window(window, q=True, tlc=True)
return [sum(x) for x in zip(TLC, WH)]
def get_layout_control(ctrl, *args):
"""Get layout's control."""
return "|".join(ctrl.split("|")[:-1])
def get_layout_config(ctrl, *args):
"""Get layout's configuration."""
return cmds.paneLayout(ctrl, q=True, configuration=True)
def get_layout_child_array(ctrl, *args):
"""Get layout's child array."""
return cmds.paneLayout(ctrl, q=True, childArray=True)
def destroy_window(*args):
"""If PlayView windows exist, destroy them."""
for w in get_windows():
if w.startswith(windowID):
cmds.deleteUI(w)
if cmds.window(helpID, exists=True):
cmds.deleteUI(helpID)
def prefs_play_all(*args):
"""Check user prefs for viewport playback type."""
return cmds.playbackOptions(q=True, v=True) == "active"
def init(*args):
"""Funtion to call to start the script."""
destroy_window()
if cmds.play(q=True, state=True) is True:
play_button()
elif not prefs_play_all():
play_button()
log.info("Playback prefs set to update all viewports.")
elif custom_viewport == "":
draw_PlayView('PlayView')
else:
play_view(custom_viewport)