Source code for cgl.plugins.AlchemyScene
import importlib
import logging
import os
from cgl.ui.widgets.dialog import InputDialog
from cgl.core.path.object import PathObject
[docs]
class Scene(object):
path = None
filename = None
source_dir = None
render_dir = None
path_object = None
def __init__(self):
self.set_path_object()
self.set_scene_path()
self.set_render_path()
[docs]
@staticmethod
def get_scene_path():
return ""
[docs]
def get_path_object(self):
return PathObject().from_path_string(self.path)
[docs]
def set_path_object(self):
self.path_object = self.get_path_object()
[docs]
def set_scene_path(self):
self.path = self.get_scene_path()
if not self.path:
raise ValueError("Maya scene is not within alchemy folder structure.")
self.source_dir, self.filename = os.path.split(self.path)
[docs]
def set_render_path(self):
self.render_dir = self.path_object.get_render_path(dirname=True)
# for some reason - this returns a path with "render" as the entity type when done this way.
# COMMON DCC FUNCTIONS
[docs]
@staticmethod
def import_file(file_path: str):
pass
[docs]
@staticmethod
def open_file(file_path: str):
pass
[docs]
def save_file(self):
pass
[docs]
def save_file_as(self, file_path: str):
pass
[docs]
@staticmethod
def select(items: list):
pass
[docs]
@staticmethod
def deselect():
pass
[docs]
@staticmethod
def export_selected(file_path, ext):
pass
# COMMON ALCHEMY SHELF ITEMS
[docs]
def build(self):
self.preflight_dialog(preflight_type="build")
pass
[docs]
def version_up(self):
"""Creates a new minor version on disk of the current "Scene()".
Assumes a minor version as a "publish" would create a major version.
it only creates files in the "source" directory, as "product" files
will be created as a result of work on the new version.
Returns:
None
"""
pass
[docs]
def preflight_dialog(self, preflight_type: str):
import cgl.plugins.preflight.main as main
pf_mw = main.Preflight(
parent=None,
software="maya",
preflight=self.path_object.task,
path_object=self.path_object,
pf_type=preflight_type,
use_threads=False,
)
pf_mw.exec()
[docs]
def create_turntable(self):
pass
[docs]
def clean_turntable(self):
pass
[docs]
def preview(self):
pass
[docs]
def render(self):
"""
Launches the preflight dialog for the current scene based off what's available in the alchemist's cookbook.
"""
self.preflight_dialog(task=self.path_object.task, preflight_type="render")
[docs]
def review(self):
"""
Checks for review media in the folder structure for the current version,
if it finds it, goes through the magic_browser "review" process for
this media type. This typically consists of:
1) Check for existing renders
2) Create jpg proxies of the renders
3) Create a mov from the jpg proxies.
4) Upload mov to review platform (like shotgrid)
5) Launch URL for the review.
Returns:
URL
"""
pass
[docs]
def publish(self):
self.preflight_dialog(preflight_type="publish")
[docs]
def export_msd(self):
task_class = self.get_class(self.path_object.task)
task_class.write_msd()
# SMART TASK FUNCTIONS
[docs]
@staticmethod
def get_class(task):
"""Gets the smart task class that relates to the specified task.
If no task is specified, the task for the current scene will be used.
Args:
task (str): The name of the task to get the class for.
Returns:
class_ (class): the class for the specified task.
"""
software = os.path.split(os.path.dirname(__file__))[-1]
module = "plugins.{}.tasks.{}".format(software, task)
module_name = task
loaded_module = importlib.import_module(module, module_name)
class_ = getattr(loaded_module, "Task")
return class_
[docs]
def import_task(self, task: str, **kwargs):
"""
Imports the latest version of the specified task into the scene.
Args:
task: the task to import.
**kwargs: Used to pass additional arguments to the import_latest() function of the task class.
Returns:
class_: the class for the specified task.
"""
if not task:
logging.exception("No Task Provided to import_task()")
return
class_ = self.get_class(task)
if class_:
return class_().import_latest(**kwargs)
else:
logging.exception("No Class Found for Task: {}".format(task))
# COMMON UTILITY FUNCTIONS
[docs]
def confirm_prompt(self):
pass
[docs]
def screen_grab(self, dialog=False):
"""Allows the user to capture a thumbnail for the current scene.
Pops open a screen capture window and when you grab the screen it does the following:
1) Create preview file for current scene_object()
2) Creates thumb_file for current scene_object()
3) Updates Project Management with new thumbnail.
Returns:
bool: True if the thumbnail was captured successfully, otherwise False.
"""
from cgl.core.utils.general import screen_grab
if dialog:
dialog = InputDialog(
title="Capture Thumbnail",
buttons=["yes", "no"],
message="Are you ready to capture a thumbnail?\n"
' If "no" hit the thumbnail button on the Alchemy Shelf when ready.',
)
dialog.exec()
if dialog.button == "yes":
screen_grab(self.scene_object())
return True
else:
return False
else:
screen_grab(self.scene_object())
return True
[docs]
def setup_alchemy_plugin(self, version):
"""Function designed to set up the application to autoload magic_browser tools and cookbook menus.
Args:
version (str): The version of the magic_browser plugin to load.
Returns:
None
"""
pass
[docs]
def get_shot_cam(self):
"""
Returns the name of the shot camera for the current shot.
"""
so = self.path_object
camera = "cam{}_{}".format(so.sequence, so.shot)
return camera