From 629b49c18209652f1c3a931e1f06b791b0180d92 Mon Sep 17 00:00:00 2001 From: Jakub Trllo <43494761+iLLiCiTiT@users.noreply.github.com> Date: Thu, 11 Jan 2024 16:15:45 +0100 Subject: [PATCH] Blender: Workfile instance update fix (#6048) * make sure workfile instance has always available 'instance_node' * create CONTAINERS node if does not exist yet --- .../blender/plugins/create/create_workfile.py | 34 +++++++++++-------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/openpype/hosts/blender/plugins/create/create_workfile.py b/openpype/hosts/blender/plugins/create/create_workfile.py index ceec3e0552..6b168f4c84 100644 --- a/openpype/hosts/blender/plugins/create/create_workfile.py +++ b/openpype/hosts/blender/plugins/create/create_workfile.py @@ -25,7 +25,7 @@ class CreateWorkfile(BaseCreator, AutoCreator): def create(self): """Create workfile instances.""" - existing_instance = next( + workfile_instance = next( ( instance for instance in self.create_context.instances if instance.creator_identifier == self.identifier @@ -39,14 +39,14 @@ class CreateWorkfile(BaseCreator, AutoCreator): host_name = self.create_context.host_name existing_asset_name = None - if existing_instance is not None: + if workfile_instance is not None: if AYON_SERVER_ENABLED: - existing_asset_name = existing_instance.get("folderPath") + existing_asset_name = workfile_instance.get("folderPath") if existing_asset_name is None: - existing_asset_name = existing_instance["asset"] + existing_asset_name = workfile_instance["asset"] - if not existing_instance: + if not workfile_instance: asset_doc = get_asset_by_name(project_name, asset_name) subset_name = self.get_subset_name( task_name, task_name, asset_doc, project_name, host_name @@ -66,19 +66,18 @@ class CreateWorkfile(BaseCreator, AutoCreator): asset_doc, project_name, host_name, - existing_instance, + workfile_instance, ) ) self.log.info("Auto-creating workfile instance...") - current_instance = CreatedInstance( + workfile_instance = CreatedInstance( self.family, subset_name, data, self ) - instance_node = bpy.data.collections.get(AVALON_CONTAINERS, {}) - current_instance.transient_data["instance_node"] = instance_node - self._add_instance_to_context(current_instance) + self._add_instance_to_context(workfile_instance) + elif ( existing_asset_name != asset_name - or existing_instance["task"] != task_name + or workfile_instance["task"] != task_name ): # Update instance context if it's different asset_doc = get_asset_by_name(project_name, asset_name) @@ -86,12 +85,17 @@ class CreateWorkfile(BaseCreator, AutoCreator): task_name, task_name, asset_doc, project_name, host_name ) if AYON_SERVER_ENABLED: - existing_instance["folderPath"] = asset_name + workfile_instance["folderPath"] = asset_name else: - existing_instance["asset"] = asset_name + workfile_instance["asset"] = asset_name - existing_instance["task"] = task_name - existing_instance["subset"] = subset_name + workfile_instance["task"] = task_name + workfile_instance["subset"] = subset_name + + instance_node = bpy.data.collections.get(AVALON_CONTAINERS) + if not instance_node: + instance_node = bpy.data.collections.new(name=AVALON_CONTAINERS) + workfile_instance.transient_data["instance_node"] = instance_node def collect_instances(self):