Merge pull request #6070 from ynput/bugfix/OP-7597-blender_fix-long-instance-names

Blender: Fix long names for instances
This commit is contained in:
Simone Barbieri 2024-01-12 15:12:05 +00:00 committed by GitHub
commit 2af78ce4ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 6 deletions

View file

@ -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"]
)

View file

@ -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)

View file

@ -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

View file

@ -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