From 875ca5cd6fd4f0da67b2dba80897dd27b6505bda Mon Sep 17 00:00:00 2001 From: Simone Barbieri Date: Mon, 24 Feb 2020 16:26:10 +0000 Subject: [PATCH] Extraction for blend files is now handled by a single class --- .../blender/publish/collect_current_file.py | 2 + ...{extract_animation.py => extract_blend.py} | 93 +++++++++---------- pype/plugins/blender/publish/extract_model.py | 47 ---------- pype/plugins/blender/publish/extract_rig.py | 47 ---------- 4 files changed, 48 insertions(+), 141 deletions(-) rename pype/plugins/blender/publish/{extract_animation.py => extract_blend.py} (86%) delete mode 100644 pype/plugins/blender/publish/extract_model.py delete mode 100644 pype/plugins/blender/publish/extract_rig.py diff --git a/pype/plugins/blender/publish/collect_current_file.py b/pype/plugins/blender/publish/collect_current_file.py index a097c72047..926d290b31 100644 --- a/pype/plugins/blender/publish/collect_current_file.py +++ b/pype/plugins/blender/publish/collect_current_file.py @@ -14,3 +14,5 @@ class CollectBlenderCurrentFile(pyblish.api.ContextPlugin): """Inject the current working file""" current_file = bpy.data.filepath context.data['currentFile'] = current_file + + assert current_file != '', "Current file is empty. Save the file before continuing." diff --git a/pype/plugins/blender/publish/extract_animation.py b/pype/plugins/blender/publish/extract_blend.py similarity index 86% rename from pype/plugins/blender/publish/extract_animation.py rename to pype/plugins/blender/publish/extract_blend.py index dbfe29af83..7e11e9ef8d 100644 --- a/pype/plugins/blender/publish/extract_animation.py +++ b/pype/plugins/blender/publish/extract_blend.py @@ -1,47 +1,46 @@ -import os -import avalon.blender.workio - -import pype.api - - -class ExtractAnimation(pype.api.Extractor): - """Extract as animation.""" - - label = "Animation" - hosts = ["blender"] - families = ["animation"] - optional = True - - def process(self, instance): - # Define extract output file path - - stagingdir = self.staging_dir(instance) - filename = f"{instance.name}.blend" - filepath = os.path.join(stagingdir, filename) - - # Perform extraction - self.log.info("Performing extraction..") - - # Just save the file to a temporary location. At least for now it's no - # problem to have (possibly) extra stuff in the file. - avalon.blender.workio.save_file(filepath, copy=True) - # - # # Store reference for integration - # if "files" not in instance.data: - # instance.data["files"] = list() - # - # # instance.data["files"].append(filename) - - if "representations" not in instance.data: - instance.data["representations"] = [] - - representation = { - 'name': 'blend', - 'ext': 'blend', - 'files': filename, - "stagingDir": stagingdir, - } - instance.data["representations"].append(representation) - - - self.log.info("Extracted instance '%s' to: %s", instance.name, representation) +import os +import avalon.blender.workio + +import pype.api + + +class ExtractBlend(pype.api.Extractor): + """Extract a blend file.""" + + label = "Extract Blend" + hosts = ["blender"] + families = ["animation", "model", "rig"] + optional = True + + def process(self, instance): + # Define extract output file path + + stagingdir = self.staging_dir(instance) + filename = f"{instance.name}.blend" + filepath = os.path.join(stagingdir, filename) + + # Perform extraction + self.log.info("Performing extraction..") + + # Just save the file to a temporary location. At least for now it's no + # problem to have (possibly) extra stuff in the file. + avalon.blender.workio.save_file(filepath, copy=True) + # + # # Store reference for integration + # if "files" not in instance.data: + # instance.data["files"] = list() + # + # # instance.data["files"].append(filename) + + if "representations" not in instance.data: + instance.data["representations"] = [] + + representation = { + 'name': 'blend', + 'ext': 'blend', + 'files': filename, + "stagingDir": stagingdir, + } + instance.data["representations"].append(representation) + + self.log.info("Extracted instance '%s' to: %s", instance.name, representation) diff --git a/pype/plugins/blender/publish/extract_model.py b/pype/plugins/blender/publish/extract_model.py deleted file mode 100644 index 501c4d9d5c..0000000000 --- a/pype/plugins/blender/publish/extract_model.py +++ /dev/null @@ -1,47 +0,0 @@ -import os -import avalon.blender.workio - -import pype.api - - -class ExtractModel(pype.api.Extractor): - """Extract as model.""" - - label = "Model" - hosts = ["blender"] - families = ["model"] - optional = True - - def process(self, instance): - # Define extract output file path - - stagingdir = self.staging_dir(instance) - filename = f"{instance.name}.blend" - filepath = os.path.join(stagingdir, filename) - - # Perform extraction - self.log.info("Performing extraction..") - - # Just save the file to a temporary location. At least for now it's no - # problem to have (possibly) extra stuff in the file. - avalon.blender.workio.save_file(filepath, copy=True) - # - # # Store reference for integration - # if "files" not in instance.data: - # instance.data["files"] = list() - # - # # instance.data["files"].append(filename) - - if "representations" not in instance.data: - instance.data["representations"] = [] - - representation = { - 'name': 'blend', - 'ext': 'blend', - 'files': filename, - "stagingDir": stagingdir, - } - instance.data["representations"].append(representation) - - - self.log.info("Extracted instance '%s' to: %s", instance.name, representation) diff --git a/pype/plugins/blender/publish/extract_rig.py b/pype/plugins/blender/publish/extract_rig.py deleted file mode 100644 index 8a3c83d07c..0000000000 --- a/pype/plugins/blender/publish/extract_rig.py +++ /dev/null @@ -1,47 +0,0 @@ -import os -import avalon.blender.workio - -import pype.api - - -class ExtractRig(pype.api.Extractor): - """Extract as rig.""" - - label = "Rig" - hosts = ["blender"] - families = ["rig"] - optional = True - - def process(self, instance): - # Define extract output file path - - stagingdir = self.staging_dir(instance) - filename = f"{instance.name}.blend" - filepath = os.path.join(stagingdir, filename) - - # Perform extraction - self.log.info("Performing extraction..") - - # Just save the file to a temporary location. At least for now it's no - # problem to have (possibly) extra stuff in the file. - avalon.blender.workio.save_file(filepath, copy=True) - # - # # Store reference for integration - # if "files" not in instance.data: - # instance.data["files"] = list() - # - # # instance.data["files"].append(filename) - - if "representations" not in instance.data: - instance.data["representations"] = [] - - representation = { - 'name': 'blend', - 'ext': 'blend', - 'files': filename, - "stagingDir": stagingdir, - } - instance.data["representations"].append(representation) - - - self.log.info("Extracted instance '%s' to: %s", instance.name, representation)