import bpy from .import fn class GPEXP_OT_render_scene_switch(bpy.types.Operator): bl_idname = "gp.render_scene_switch" bl_label = "Render Scene Switch" bl_description = "Switch between render" bl_options = {"REGISTER"} @classmethod def poll(cls, context): return True # mode : bpy.props.StringProperty(default='NORMAL', options={'SKIP_SAVE'}) def execute(self, context): scenes = bpy.data.scenes if len(scenes) < 2: self.report({'ERROR'},'No other scene to go to') return {"CANCELLED"} if context.scene.name == 'Render': scn = scenes.get('Scene') if not scn: # get the next available scene self.report({'WARNING'},'No scene named "Scene"') slist = [s.name for s in scenes] scn = scenes[(slist.index(bpy.context.scene.name) + 1) % len(scenes)] else: scn = scenes.get('Render') if not scn: self.report({'ERROR'},'No "Render" scene yet') return {"CANCELLED"} self.report({'INFO'},f'Switched to scene "{scn.name}"') bpy.context.window.scene = scn return {"FINISHED"} class GPEXP_OT_swap_render_cams(bpy.types.Operator): bl_idname = "gp.swap_render_cams" bl_label = "Swap Cameras" bl_description = "Toggle between anim and bg cam" bl_options = {"REGISTER"} def execute(self, context): anim_cam = bpy.context.scene.objects.get('anim_cam') bg_cam = bpy.context.scene.objects.get('bg_cam') if not anim_cam or not bg_cam: self.report({'ERROR'}, 'anim_cam or bg_cam is missing') return {"CANCELLED"} cam = context.scene.camera if not cam: context.scene.camera = anim_cam fn.set_resolution_from_cam_prop() return {"FINISHED"} in_draw = False if cam.parent and cam.name in ('draw_cam', 'action_cam'): if cam.name == 'draw_cam': draw_cam = cam in_draw = True cam = cam.parent ## swap # context.scene.camera = bg_cam if cam is anim_cam else anim_cam if cam is anim_cam: main = context.scene.camera = bg_cam anim_cam.hide_viewport = True bg_cam.hide_viewport = False else: main = context.scene.camera = anim_cam anim_cam.hide_viewport = False bg_cam.hide_viewport = True if in_draw: draw_cam.parent = main draw_cam.data = main.data # back in draw_cam context.scene.camera = draw_cam bg_cam.hide_viewport = anim_cam.hide_viewport = True # set res ret = fn.set_resolution_from_cam_prop(main) if ret: self.report({ret[0]}, ret[1]) return {"FINISHED"} classes=( GPEXP_OT_render_scene_switch, GPEXP_OT_swap_render_cams, ) def register(): for cls in classes: bpy.utils.register_class(cls) def unregister(): for cls in reversed(classes): bpy.utils.unregister_class(cls)