1
$\begingroup$

I've created 3 cameras in my scene and I need to go from the first to the last always in camera view.

What's wrong is that if I start my code in camera perspective, the camera changes and so do the view correctly.

But if i launch my code in user perspective, the cameras will switch correctly but the view not until the end, where it will go in the last camera's perspective

for w in bpy.context.window_manager.windows:
    s = w.screen
    for a in s:
        if a.type = 'VIEW_3D':
            for r in a.regions:
                if r.type='WINDOW':
                    override = {'window':w, 'screen':s, 'area':a, 'region':r}    

by.ops.view3d.viewnumpad(override, type='CAMERA')
for c in [c for c in bpy.context.scene.objects if c.type == 'CAMERA']:
    bpy.context.scene.camera = c
    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations = 1)

Seems like the viewnumpad() is not triggering correctly the view before the switching. How can fix it?

$\endgroup$
7
  • $\begingroup$ is the same code you are running ? there is an error in REDRAW_WIN_SWAP $\endgroup$
    – Chebhou
    Commented Mar 23, 2015 at 11:19
  • $\begingroup$ pardon, I forgot the override for the view_numpad() context. Edited. $\endgroup$
    – UncleSax
    Commented Mar 23, 2015 at 11:25
  • $\begingroup$ no i did the override part but as i said there is no REDRAW_WIN_swap $\endgroup$
    – Chebhou
    Commented Mar 23, 2015 at 11:27
  • $\begingroup$ still my fault. It's DRAW_WIN_SWAP....don't know why I wrote that :) $\endgroup$
    – UncleSax
    Commented Mar 23, 2015 at 11:28
  • $\begingroup$ did you take a look at this DOC $\endgroup$
    – Chebhou
    Commented Mar 23, 2015 at 11:36

1 Answer 1

0
$\begingroup$

The problem appears clearly when moving from any view to camera_view but it is also present when moving from camera_view to another (you can see that the view change from camera than hold still and then change at last) and it is caused by the ED_view3d_smooth_view_ex() ( source code ) function and as you can see in the source code it is skipped if you are in render view , so for checking you can switch to render view and the code will run as expected

here some code to make the transition clear (watch the view and console ) :

def main(context):
    print('******************************************************')
    bpy.ops.view3d.viewnumpad(type='CAMERA')
    bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations = 1)
    print('sleep')
    time.sleep(8)
    print('wake')

( it may have something to do with timers )

$\endgroup$
2
  • $\begingroup$ you're right, in render view it works correctly. Otherwise I can't do it in this way because if my scene starts to be heavy, any transition will require too much time; in this case doing it starting from the a camera view will be lighter. By the way thanks a lot for your time! $\endgroup$
    – UncleSax
    Commented Mar 23, 2015 at 14:42
  • $\begingroup$ @UncleSax you're welcome, and if it is critical to your application ask the developers for any work around $\endgroup$
    – Chebhou
    Commented Mar 23, 2015 at 14:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .