From d43a80945d18b8aac8afc38e73c0629150911627 Mon Sep 17 00:00:00 2001 From: wijnand Date: Thu, 28 Jun 2018 17:52:39 +0200 Subject: [PATCH] implemented setting project fps --- colorbleed/lib.py | 20 ++++++++++++++++++++ colorbleed/maya/__init__.py | 7 +++++-- colorbleed/maya/lib.py | 20 +++++++++++++++++++- 3 files changed, 44 insertions(+), 3 deletions(-) diff --git a/colorbleed/lib.py b/colorbleed/lib.py index 8e1d0becc6..e93296fbc0 100644 --- a/colorbleed/lib.py +++ b/colorbleed/lib.py @@ -247,3 +247,23 @@ def collect_container_metadata(container): return {} return hostlib.get_additional_data(container) + + +def get_project_fps(): + """Returns project's FPS, if not found will return 25 by default + + Returns: + int, float + """ + + project_name = io.active_project() + project = io.find_one({"name": project_name, + "type": "project"}, + projection={"config.fps": True}) + + config = project.get("config", None) + assert config, "This is a bug" + + fps = config.get("fps", 25) + + return fps diff --git a/colorbleed/maya/__init__.py b/colorbleed/maya/__init__.py index 0e21125666..008d5229ce 100644 --- a/colorbleed/maya/__init__.py +++ b/colorbleed/maya/__init__.py @@ -2,8 +2,7 @@ import os import logging import weakref -from maya import utils -from maya import cmds +from maya import utils, cmds from avalon import api as avalon, pipeline, maya from pyblish import api as pyblish @@ -94,6 +93,7 @@ def on_init(_): from .customize import override_component_mask_commands safe_deferred(override_component_mask_commands) + safe_deferred(lib.set_project_fps) def on_save(_): @@ -119,6 +119,9 @@ def on_open(_): from avalon.vendor.Qt import QtWidgets from ..widgets import popup + # Ensure scene's FPS is set to project config + lib.set_project_fps() + # Update current task for the current scene update_task_from_path(cmds.file(query=True, sceneName=True)) diff --git a/colorbleed/maya/lib.py b/colorbleed/maya/lib.py index 1493f7385e..1faad51d99 100644 --- a/colorbleed/maya/lib.py +++ b/colorbleed/maya/lib.py @@ -13,7 +13,7 @@ from collections import OrderedDict, defaultdict from maya import cmds, mel from avalon import api, maya, io, pipeline -from cb.utils.maya import core +from colorbleed import lib import cb.utils.maya.context @@ -1292,3 +1292,21 @@ def get_id_from_history(node): _id = get_id(similar_node) if _id: return _id + + +def set_project_fps(): + """Set FPS from project configuration""" + + fps = lib.get_project_fps() + if not isinstance(fps, (int, float)): + raise ValueError("Set value for project's FPS is not a number. " + "Only accepts floats and integers") + + if int(fps) == 24: + cmds.currentUnit(time="film") + log.info("Updated FPS to 24 (film)") + elif int(fps) == 25: + cmds.currentUnit(time="pal") + log.info("Updated FPS to 25 (pal)") + else: + raise RuntimeError("Cannot translate FPS: `%s`" % fps)