Source code for cgl.plugins.blender.tasks.smart_task
import logging
[docs]
class SmartTask(object):
"""
This is a template for a "task" within the cookbook. It covers common areas when dealing with digital assets
specific to different tasks.
"""
def __init__(self, path_object=None):
"""
Args:
path_object (PathObject, optional): PathObject instance. Defaults to None.
"""
from cgl.plugins.blender.alchemy import scene_object
from cgl.core.path.object import PathObject
if not path_object:
self.path_object = scene_object()
else:
self.path_object = path_object
if not isinstance(path_object, PathObject):
logging.info("{} is not instance PathObject")
return
logging.info(path_object.get_path())
# check if it's a PathObject instance
[docs]
def build(self):
"""
the tasks code associated with this task.
Returns:
"""
pass
def _import(self, file_path, reference=False, **kwargs):
"""
Imports the file into the scene - this function should be smart enough to handle various file types
as well as
Returns:
"""
if not file_path:
file_path = self.path_object.get_path()
from cgl.plugins.blender.alchemy import import_file, reference_file, PathObject
path_object = PathObject(file_path)
if reference:
return reference_file(filepath=file_path)
else:
logging.info(file_path)
return import_file(filepath=file_path)
[docs]
def import_latest(self, task=None, reference=False, **kwargs):
if not task:
task = self.path_object.task
new_obj = self.path_object.copy(
task=task,
tree="render",
user="publish",
latest=True,
set_filename=True,
)
import_obj = self._import(new_obj.get_path(), reference=reference)
return import_obj
[docs]
def publish(self):
"""Publishes specific to the task at hand. by default we just do what's in the magic_browser plugin,
this allows us to customize at a more granular level if needed.
Returns:
"""
from cgl.plugins.blender.alchemy import publish
publish()
[docs]
def get_msd_data(self):
"""Creates the msd dictionary for the task being called.
Args:
task_name (str): task name
"""
pass
[docs]
def render(self):
""" """
pass
[docs]
def get_objects(self, group="high", namespace=None, default_ns=True):
"""
Returns:
A list of tuples with the objects and it's material group
"""
from cgl.plugins.blender import utils
from importlib import reload
from cgl.plugins.blender.alchemy import scene_object
reload(utils)
mdl_objects = []
group_name = group
if default_ns:
namespace = scene_object().asset
if namespace:
group_name = "{}:{}".format(namespace, group)
try:
geo_group = utils.get_object(group_name)
except KeyError:
geo_group = utils.get_object(group)
return geo_group.children