Newer
Older
layer_collection = layer_collections[new_collection.name]["ptr"]
context.view_layer.active_layer_collection = layer_collection
global rename
rename[0] = True
# reset history
for rto in rto_history.values():
rto.clear()
class CMPhantomModeOperator(Operator):
'''Toggle Phantom Mode'''
bl_label = "Toggle Phantom Mode"
bl_idname = "view3d.toggle_phantom_mode"
def execute(self, context):
global phantom_history
global rto_history
cm = context.scene.collection_manager
view_layer = context.view_layer
# save current visibility state
phantom_history["view_layer"] = view_layer.name
def save_visibility_state(layer_collection):
phantom_history["initial_state"][layer_collection.name] = {
"exclude": layer_collection.exclude,
"select": layer_collection.collection.hide_select,
"hide": layer_collection.hide_viewport,
"disable": layer_collection.collection.hide_viewport,
"render": layer_collection.collection.hide_render,
}
apply_to_children(view_layer.layer_collection, save_visibility_state)
# save current rto history
for rto, history, in rto_history.items():
if history.get(view_layer.name, None):
phantom_history[rto+"_history"] = deepcopy(history[view_layer.name])
else: # return to normal mode
def restore_visibility_state(layer_collection):
phantom_laycol = phantom_history["initial_state"][layer_collection.name]
layer_collection.exclude = phantom_laycol["exclude"]
layer_collection.collection.hide_select = phantom_laycol["select"]
layer_collection.hide_viewport = phantom_laycol["hide"]
layer_collection.collection.hide_viewport = phantom_laycol["disable"]
layer_collection.collection.hide_render = phantom_laycol["render"]
apply_to_children(view_layer.layer_collection, restore_visibility_state)
# restore previous rto history
for rto, history, in rto_history.items():
if view_layer.name in history:
del history[view_layer.name]
if phantom_history[rto+"_history"]:
history[view_layer.name] = deepcopy(phantom_history[rto+"_history"])
phantom_history[rto+"_history"].clear()