Skip to content

Commit

Permalink
Fix: loading non-outliner container (ynput#93)
Browse files Browse the repository at this point in the history
* Fix: loading non-outliner container

* fix outliner entity

* fix missing override

* fix outliner entity reference

* fix outliner not overridden

* whitespace
  • Loading branch information
Tilix4 authored Apr 17, 2023
1 parent 30acac4 commit 74781cd
Showing 1 changed file with 30 additions and 19 deletions.
49 changes: 30 additions & 19 deletions openpype/hosts/blender/api/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -741,27 +741,41 @@ 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(
bpy.context.scene,
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)
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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

Expand Down

0 comments on commit 74781cd

Please sign in to comment.