With this code fragment, I can enter the camera view correctly, but I'd like to be able to get out.

 for a in bpy.context.screen.areas: 
        if a.type == 'VIEW_3D': 
            for r in a.regions: 
                if r.type == 'WINDOW': 
                    override = {'window': bpy.context.window,
                                'area': a, 
                                'region': r,
                                'scene': bpy.context.scene,
                                'active_object': camera}
  • $\begingroup$ uh, is it important that you use python to exit? this can be done easily with a keyboard shortcut. $\endgroup$ – Millard Sep 29 '19 at 17:22
  • $\begingroup$ @Millard it is not very important, but it is necessary to understand $\endgroup$ – Pastrokkio Sep 29 '19 at 17:28
  • 1
    $\begingroup$ I was just making sure you wanted a python answer. I'm not sure how to do this in python, was just making sure you knew it could be done with a shortcut. lol. $\endgroup$ – Millard Sep 29 '19 at 17:30

You can use the view3d.viewnumpad operation.
Pass on the override context, just like in your example code. This snippet can also be used to enter the active camera's view.

bpy.ops.view3d.viewnumpad(override, type='CAMERA')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.