From c13f28ffdc4e044b887c8dd261672f428fa1376f Mon Sep 17 00:00:00 2001 From: Scott Milner Date: Mon, 7 Oct 2024 10:34:45 -0600 Subject: [PATCH 1/4] Add option for playblasting from the camera sequencer. --- capture.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/capture.py b/capture.py index 74437ff..31f6259 100644 --- a/capture.py +++ b/capture.py @@ -45,6 +45,7 @@ def capture(camera=None, overwrite=False, frame_padding=4, raw_frame_numbers=False, + sequence_time=False, camera_options=None, display_options=None, viewport_options=None, @@ -84,6 +85,10 @@ def capture(camera=None, frame numbers from the scene or capture to a sequence starting at zero. Defaults to False. When set to True `viewer` can't be used and will be forced to False. + sequence_time (bool, optional): Whether or not to playblast using the + camera sequencer. Defaults to False. When set to True the value of + `camera` will be ignored and the cameras from the sequencer will + be used instead. camera_options (dict, optional): Supplied camera options, using `CameraOptions` display_options (dict, optional): Supplied display @@ -193,6 +198,7 @@ def capture(camera=None, widthHeight=[width, height], rawFrameNumbers=raw_frame_numbers, framePadding=frame_padding, + sequenceTime=sequence_time, **playblast_kwargs) return output From 6b906cc679070c80f7f5a9fc0b04e58b1cc18ce9 Mon Sep 17 00:00:00 2001 From: Scott Milner Date: Mon, 7 Oct 2024 17:32:20 -0600 Subject: [PATCH 2/4] If sequence_time is enabled, get the default frame range from the Camera Sequencer instead of the timeline --- capture.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/capture.py b/capture.py index 31f6259..f8c5a62 100644 --- a/capture.py +++ b/capture.py @@ -88,7 +88,8 @@ def capture(camera=None, sequence_time (bool, optional): Whether or not to playblast using the camera sequencer. Defaults to False. When set to True the value of `camera` will be ignored and the cameras from the sequencer will - be used instead. + be used instead. Additionally, the `start_frame` and `end_frame` + values will be in sequence time instead of scene frame numbers. camera_options (dict, optional): Supplied camera options, using `CameraOptions` display_options (dict, optional): Supplied display @@ -130,10 +131,21 @@ def capture(camera=None, ratio = cmds.getAttr("defaultResolution.deviceAspectRatio") height = round(width / ratio) - if start_frame is None: - start_frame = cmds.playbackOptions(minTime=True, query=True) - if end_frame is None: - end_frame = cmds.playbackOptions(maxTime=True, query=True) + # Set frame range if no custom frame range specified + if sequence_time: + # Get frames from the Camera Sequencer + sequencer = cmds.sequenceManager(query=True, writableSequencer=True) + + if start_frame is None: + start_frame = cmds.getAttr(sequencer + ".minFrame") + if end_frame is None: + end_frame = cmds.getAttr(sequencer + ".maxFrame") + else: + # Get frames from the timeline + if start_frame is None: + start_frame = cmds.playbackOptions(minTime=True, query=True) + if end_frame is None: + end_frame = cmds.playbackOptions(maxTime=True, query=True) # (#74) Bugfix: `maya.cmds.playblast` will raise an error when playblasting # with `rawFrameNumbers` set to True but no explicit `frames` provided. From 99f3f295a436b1e91fdb5c7d539836959f8b7038 Mon Sep 17 00:00:00 2001 From: Scott Milner Date: Tue, 8 Oct 2024 13:11:44 -0600 Subject: [PATCH 3/4] Change argument to 'use_camera_sequencer'. Fix '_applied_camera_options' contextmanager to apply to all cameras when using the sequencer --- capture.py | 65 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 39 insertions(+), 26 deletions(-) diff --git a/capture.py b/capture.py index f8c5a62..9a2da13 100644 --- a/capture.py +++ b/capture.py @@ -7,6 +7,7 @@ import re import sys import contextlib +from collections import defaultdict from maya import cmds from maya import mel @@ -45,7 +46,7 @@ def capture(camera=None, overwrite=False, frame_padding=4, raw_frame_numbers=False, - sequence_time=False, + use_camera_sequencer=False, camera_options=None, display_options=None, viewport_options=None, @@ -85,11 +86,12 @@ def capture(camera=None, frame numbers from the scene or capture to a sequence starting at zero. Defaults to False. When set to True `viewer` can't be used and will be forced to False. - sequence_time (bool, optional): Whether or not to playblast using the - camera sequencer. Defaults to False. When set to True the value of - `camera` will be ignored and the cameras from the sequencer will - be used instead. Additionally, the `start_frame` and `end_frame` - values will be in sequence time instead of scene frame numbers. + use_camera_sequencer (bool, optional): Whether or not to playblast + using the camera sequencer. Defaults to False. When set to True the + value of `camera` will be ignored and the cameras from the + sequencer will be used instead. Additionally, the `start_frame` and + `end_frame` values will be in sequence time instead of scene frame + numbers. camera_options (dict, optional): Supplied camera options, using `CameraOptions` display_options (dict, optional): Supplied display @@ -132,7 +134,7 @@ def capture(camera=None, height = round(width / ratio) # Set frame range if no custom frame range specified - if sequence_time: + if use_camera_sequencer: # Get frames from the Camera Sequencer sequencer = cmds.sequenceManager(query=True, writableSequencer=True) @@ -189,7 +191,7 @@ def capture(camera=None, with _disabled_inview_messages(),\ _maintain_camera(panel, camera),\ _applied_viewport_options(viewport_options, panel),\ - _applied_camera_options(camera_options, panel),\ + _applied_camera_options(camera_options, panel, use_camera_sequencer),\ _applied_display_options(display_options),\ _applied_viewport2_options(viewport2_options),\ _isolated_nodes(isolate, panel),\ @@ -210,7 +212,7 @@ def capture(camera=None, widthHeight=[width, height], rawFrameNumbers=raw_frame_numbers, framePadding=frame_padding, - sequenceTime=sequence_time, + sequenceTime=use_camera_sequencer, **playblast_kwargs) return output @@ -634,30 +636,41 @@ def _independent_panel(width, height, off_screen=False): @contextlib.contextmanager -def _applied_camera_options(options, panel): - """Context manager for applying `options` to `camera`""" - - camera = cmds.modelPanel(panel, query=True, camera=True) +def _applied_camera_options(options, panel, use_camera_sequencer=False): + """Context manager for applying `options` to the cameras used""" + + if use_camera_sequencer: + cameras = [ + cmds.shot(shot, query=True, currentCamera=True) + for shot in cmds.sequenceManager(listShots=True) + if not cmds.shot(shot, query=True, mute=True) + ] + else: + cameras = [cmds.modelPanel(panel, query=True, camera=True)] + options = dict(CameraOptions, **(options or {})) - old_options = dict() - for opt in options.copy(): - try: - old_options[opt] = cmds.getAttr(camera + "." + opt) - except: - sys.stderr.write("Could not get camera attribute " - "for capture: %s" % opt) - options.pop(opt) + old_options = defaultdict(dict) + for camera in cameras: + cam_options = options.copy() + for opt in cam_options: + try: + old_options[camera][opt] = cmds.getAttr(camera + "." + opt) + except: + sys.stderr.write("Could not get camera attribute " + "for capture: %s.%s" % (camera, opt)) + cam_options.pop(opt) - for opt, value in options.items(): - cmds.setAttr(camera + "." + opt, value) + for opt, value in cam_options.items(): + cmds.setAttr(camera + "." + opt, value) try: yield finally: - if old_options: - for opt, value in old_options.items(): - cmds.setAttr(camera + "." + opt, value) + for camera, orig_options in old_options.items(): + if orig_options: + for opt, value in orig_options.items(): + cmds.setAttr(camera + "." + opt, value) @contextlib.contextmanager From 35175d33ae9db083baf7a3d45c32dda9cf03145a Mon Sep 17 00:00:00 2001 From: Marcus Ottosson Date: Thu, 10 Oct 2024 07:31:14 +0100 Subject: [PATCH 4/4] Update capture.py --- capture.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/capture.py b/capture.py index 9a2da13..74d2a08 100644 --- a/capture.py +++ b/capture.py @@ -21,7 +21,7 @@ from PySide import QtGui QtWidgets = QtGui -version_info = (2, 5, 0) +version_info = (2, 6, 0) __version__ = "%s.%s.%s" % version_info __license__ = "MIT"