diff --git a/openpype/hosts/blender/api/plugin.py b/openpype/hosts/blender/api/plugin.py index 34ba551f081..ade243040c4 100644 --- a/openpype/hosts/blender/api/plugin.py +++ b/openpype/hosts/blender/api/plugin.py @@ -741,16 +741,31 @@ def _load_library_datablocks( datacol.foreach_set("use_fake_user", seq) if self.bl_types & BL_OUTLINER_TYPES: - # Override datablocks if needed - if do_override: - # Get datablocks to override, which have no user in the loaded datablocks (orphan at this point) - datablocks_to_override = { + # Get datablocks to override, which have + # no user in the loaded datablocks (orphan at this point) + datablocks_to_override = { d for d, users in bpy.data.user_map( subset=datablocks ).items() if not users & datablocks } + + # Try to get the right asset container from imported collections. + # TODO this whole outliner entity is a bad idea + # it must be refactored to deal correctly with nested + # outliner entities using user_map() + outliner_entity = next( + ( + entity + for entity in datablocks_to_override + if entity.name.startswith(container_name) + ), + None, + ) + + # Override datablocks if needed + if do_override: datablocks = set() for d in datablocks_to_override: override_datablock = d.override_hierarchy_create( @@ -758,10 +773,9 @@ def _load_library_datablocks( bpy.context.view_layer # NOTE After BL3.4: do_fully_editable=True ) - # Ensure user override NOTE: will be unecessary after BL3.4 - override_datablock.override_library.is_system_override = ( - False - ) + + # Update outliner entity + outliner_entity = override_datablock # Update datablocks because could have been renamed datablocks.add(override_datablock) @@ -778,16 +792,10 @@ def _load_library_datablocks( set(override_datablock.all_objects) ) - # Get the right asset container from imported collections. - outliner_entity = next( - ( - entity - for entity in list(data_to.collections) - + list(data_to.objects) - if entity.name.startswith(container_name) - ), - None, - ) + # Ensure user override NOTE: will be unecessary after BL3.4 + for d in datablocks: + if hasattr(d.override_library, "is_system_override"): + d.override_library.is_system_override = False if outliner_entity: # Set color @@ -796,6 +804,8 @@ def _load_library_datablocks( # Substitute name in case renamed with .### container_name = outliner_entity.name + else: + outliner_entity = None # Put into container container = self._containerize_datablocks( @@ -804,7 +814,8 @@ def _load_library_datablocks( # Set data to container container.library = bpy.data.libraries.get(libpath.name) - container.outliner_entity = outliner_entity + if outliner_entity: + container.outliner_entity = outliner_entity return container, datablocks