diff --git a/openpype/hosts/blender/api/plugin.py b/openpype/hosts/blender/api/plugin.py index 568d8f6695..b1ff3e4a09 100644 --- a/openpype/hosts/blender/api/plugin.py +++ b/openpype/hosts/blender/api/plugin.py @@ -36,6 +36,12 @@ def prepare_scene_name( if namespace: name = f"{name}_{namespace}" name = f"{name}_{subset}" + + # Blender name for a collection or object cannot be longer than 63 + # characters. If the name is longer, it will raise an error. + if len(name) > 63: + raise ValueError(f"Scene name '{name}' would be too long.") + return name @@ -226,7 +232,7 @@ class BaseCreator(Creator): # Create asset group if AYON_SERVER_ENABLED: - asset_name = instance_data["folderPath"] + asset_name = instance_data["folderPath"].split("/")[-1] else: asset_name = instance_data["asset"] @@ -305,12 +311,16 @@ class BaseCreator(Creator): ) return - # Rename the instance node in the scene if subset or asset changed + # Rename the instance node in the scene if subset or asset changed. + # Do not rename the instance if the family is workfile, as the + # workfile instance is included in the AVALON_CONTAINER collection. if ( "subset" in changes.changed_keys or asset_name_key in changes.changed_keys - ): + ) and created_instance.family != "workfile": asset_name = data[asset_name_key] + if AYON_SERVER_ENABLED: + asset_name = asset_name.split("/")[-1] name = prepare_scene_name( asset=asset_name, subset=data["subset"] ) diff --git a/openpype/hosts/blender/plugins/load/load_animation.py b/openpype/hosts/blender/plugins/load/load_animation.py index 3e7f808903..fd087553f0 100644 --- a/openpype/hosts/blender/plugins/load/load_animation.py +++ b/openpype/hosts/blender/plugins/load/load_animation.py @@ -61,5 +61,10 @@ class BlendAnimationLoader(plugin.AssetLoader): bpy.data.objects.remove(container) - library = bpy.data.libraries.get(bpy.path.basename(libpath)) + filename = bpy.path.basename(libpath) + # Blender has a limit of 63 characters for any data name. + # If the filename is longer, it will be truncated. + if len(filename) > 63: + filename = filename[:63] + library = bpy.data.libraries.get(filename) bpy.data.libraries.remove(library) diff --git a/openpype/hosts/blender/plugins/load/load_blend.py b/openpype/hosts/blender/plugins/load/load_blend.py index f437e66795..2d5ac18149 100644 --- a/openpype/hosts/blender/plugins/load/load_blend.py +++ b/openpype/hosts/blender/plugins/load/load_blend.py @@ -106,7 +106,12 @@ class BlendLoader(plugin.AssetLoader): bpy.context.scene.collection.objects.link(obj) # Remove the library from the blend file - library = bpy.data.libraries.get(bpy.path.basename(libpath)) + filepath = bpy.path.basename(libpath) + # Blender has a limit of 63 characters for any data name. + # If the filepath is longer, it will be truncated. + if len(filepath) > 63: + filepath = filepath[:63] + library = bpy.data.libraries.get(filepath) bpy.data.libraries.remove(library) return container, members diff --git a/openpype/hosts/blender/plugins/load/load_blendscene.py b/openpype/hosts/blender/plugins/load/load_blendscene.py index 6cc7f39d03..fba0245af1 100644 --- a/openpype/hosts/blender/plugins/load/load_blendscene.py +++ b/openpype/hosts/blender/plugins/load/load_blendscene.py @@ -60,7 +60,12 @@ class BlendSceneLoader(plugin.AssetLoader): bpy.context.scene.collection.children.link(container) # Remove the library from the blend file - library = bpy.data.libraries.get(bpy.path.basename(libpath)) + filepath = bpy.path.basename(libpath) + # Blender has a limit of 63 characters for any data name. + # If the filepath is longer, it will be truncated. + if len(filepath) > 63: + filepath = filepath[:63] + library = bpy.data.libraries.get(filepath) bpy.data.libraries.remove(library) return container, members