Collection Manager: Fix remove operator. Task: T69577

Fixes the remove operator not preserving View Layer RTOs for
the children of the deleted collection.
This commit is contained in:
Ryan Inch 2020-07-03 03:13:10 -04:00
parent 9128155de3
commit 969e77eda1
2 changed files with 26 additions and 2 deletions

View File

@ -22,7 +22,7 @@ bl_info = {
"name": "Collection Manager",
"description": "Manage collections and their objects",
"author": "Ryan Inch",
"version": (2, 9, 0),
"version": (2, 9, 1),
"blender": (2, 80, 0),
"location": "View3D - Object Mode (Shortcut - M)",
"warning": '', # used for warning icon and text in addons panel

View File

@ -883,11 +883,35 @@ class CMRemoveCollectionOperator(Operator):
parent_collection.objects.link(obj)
# shift all child collections to the parent collection
# shift all child collections to the parent collection preserving view layer RTOs
if collection.children:
# store view layer RTOs for all children of the to be deleted collection
child_states = {}
def get_child_states(layer_collection):
child_states[layer_collection.name] = (layer_collection.exclude,
layer_collection.hide_viewport,
layer_collection.holdout,
layer_collection.indirect_only)
apply_to_children(laycol["ptr"], get_child_states)
# link any subcollections of the to be deleted collection to it's parent
for subcollection in collection.children:
parent_collection.children.link(subcollection)
# apply the stored view layer RTOs to the newly linked collections and their
# children
def restore_child_states(layer_collection):
state = child_states.get(layer_collection.name)
if state:
layer_collection.exclude = state[0]
layer_collection.hide_viewport = state[1]
layer_collection.holdout = state[2]
layer_collection.indirect_only = state[3]
apply_to_children(laycol["parent"]["ptr"], restore_child_states)
# remove collection, update expanded, and update tree view
bpy.data.collections.remove(collection)