import bpy from bpy.props import IntProperty from . import page_manager from .guides import rebuild_guides class EDITORIALGP_OT_create_document(bpy.types.Operator): bl_idname = "editorial_gp.create_document" bl_label = "Create Editorial Document" bl_options = {'REGISTER', 'UNDO'} page_count: IntProperty(name="Page Count", default=4, min=1, max=100) def invoke(self, context, event): return context.window_manager.invoke_props_dialog(self) def execute(self, context): scene = context.scene existing = page_manager.page_collections(scene) if existing: self.report({'ERROR'}, "An editorial document already exists in the scene") return {'CANCELLED'} page_manager.ensure_root(scene) page_manager.ensure_guides_collection(scene) for _ in range(self.page_count): page_manager.create_page(scene) scene.editorial_gp.initialized = True scene.editorial_gp.current_page_index = 0 page_manager.set_active_page(scene, 0, context.view_layer) rebuild_guides(scene) self.report({'INFO'}, f"Document created with {self.page_count} pages") return {'FINISHED'} class EDITORIALGP_OT_apply_document_settings(bpy.types.Operator): bl_idname = "editorial_gp.apply_document_settings" bl_label = "Apply Format and Guides" bl_options = {'REGISTER', 'UNDO'} def execute(self, context): rebuild_guides(context.scene) self.report({'INFO'}, "Format and guides updated") return {'FINISHED'} classes = (EDITORIALGP_OT_create_document, EDITORIALGP_OT_apply_document_settings) def register(): for cls in classes: bpy.utils.register_class(cls) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls)