Camera view and viewport

it looks simple but I can’t find the right info anywhere :

I want to be sure that the camera view is active in the viewport. the only way I found so far is :


bpy.ops.view3d.viewnumpad(type='FRONT') # select front view..
bpy.ops.view3d.viewnumpad(type='CAMERA') # ..to be sure to have the camera view after that

:eek::no:

is there a boolean or something that would give the viewport view status ?

… or is there a way to temporary freeze the blender ui refresh ?

<i>bpy.ops.wm.freezeUi()</i>
bpy.ops.view3d.viewnumpad(type='FRONT') # select front view..
bpy.ops.view3d.viewnumpad(type='CAMERA') # ..to be sure to have the camera view after that
<i>bpy.ops.wm.refreshUi()</i>

Hello,
I dont find an other way too…
And to freeze the blender ui, I think it is not possible and not desirable :slight_smile:

Bon courage.

ok there’s two of us then :slight_smile:

I got this now, no ‘view jumps’ anymore :

import bpy

class camview(bpy.types.Operator):
    bl_idname = "wm.view3d_cam"
    bl_label = "camera view"
    
    def execute(self,context) :
        bpy.ops.object.select_camera()
        bpy.ops.view3d.object_as_camera()
        return {'FINISHED'}
    
bpy.utils.register_class(camview)

altP then space in the viewport and type ‘camera view’

It’s a good solution littleneo!

But i’d still like to know how to know what the active viewport is set to, say as in the case of zeffii’s dimensioning tool it could decide how to orient the text, or various situations it would be very helpful to know (allowing for more intuitive tools).

I’m not sure but you should be able to retrieve the current view matrix, wether the camera is used or not.

I found an other way:
http://www.blender.org/documentation/blender_python_api_2_57_release/bpy.types.RegionView3D.html#bpy.types.RegionView3D

a short example with the default UI:


import bpy
 
bpy.context.screen.areas[5].spaces[0].region_3d.view_perspective = 'CAMERA'

2 Likes

nice !
matrices are there too.

Excellent.
I have created a script with applicability.

use region_3d

import bpy


for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':

        area.spaces.active.region_3d.view_perspective = 'CAMERA'

use ops

import bpy

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        override = {'area': area, 'region': area.regions} #override context
        bpy.ops.view3d.view_camera(override)