import bpy from bpy.props import (BoolProperty, EnumProperty, PointerProperty, CollectionProperty, StringProperty) from .. import fn class RT_OT_store_visibility_states(bpy.types.Operator): """Store visibility states of objects and collections""" bl_idname = "rt.store_visibility_states" bl_label = "Store Visibility States" bl_options = {'REGISTER', 'UNDO'} collection_name: StringProperty( name="Collection Name", description="Name of the collection to store viewlayer states of a collection childrens. Leave empty for all.", default="" ) def execute(self, context): if self.collection_name == "ALL-SCENE-COLLECTION": # Store scene collection (under key "ALL") fn.store_collection_states(None, context=context) return {'FINISHED'} # next((c for c in context.scene.collection.children_recursive if c.name == collection_name), None) col = fn.get_target_collection(self.collection_name, context=context) fn.store_collection_states(col, context=context) return {'FINISHED'} class RT_OT_apply_visibility_states(bpy.types.Operator): """Apply stored visibility states to objects and collections""" bl_idname = "rt.apply_visibility_states" bl_label = "Apply Visibility States" bl_options = {'REGISTER', 'UNDO'} collection_name: StringProperty( name="Collection Name", description="Name of the collection to apply visibility states for. Leave empty for all.", default="" ) def execute(self, context): if self.collection_name == "ALL-SCENE-COLLECTION": # Apply scene collection (under key "ALL") ret = fn.apply_collection_states(None, context=context) if isinstance(ret, tuple): self.report(ret[0], ret[1]) return {'FINISHED'} # next((c for c in context.scene.collection.children_recursive if c.name == collection_name), None) col = fn.get_target_collection(self.collection_name, context=context) ret = fn.apply_collection_states(col, context=context) if isinstance(ret, tuple): self.report(ret[0], ret[1]) return {'FINISHED'} class RT_OT_delete_visibility_states(bpy.types.Operator): """Delete stored visibility states from scene""" bl_idname = "rt.delete_visibility_states" bl_label = "Delete Visibility States" bl_options = {'REGISTER', 'UNDO'} collection_name: StringProperty( name="Collection Name", description="Name of the collection to delete visibility states for. Leave empty for all.", default="" ) def execute(self, context): fn.delete_collection_states(self.collection_name, context=context) return {'FINISHED'} def register(): bpy.utils.register_class(RT_OT_store_visibility_states) bpy.utils.register_class(RT_OT_apply_visibility_states) bpy.utils.register_class(RT_OT_delete_visibility_states) def unregister(): bpy.utils.unregister_class(RT_OT_store_visibility_states) bpy.utils.unregister_class(RT_OT_apply_visibility_states) bpy.utils.unregister_class(RT_OT_delete_visibility_states)