1
$\begingroup$

I want to align the 3D view like the menu item "View/Align View/Center Cursor and View All" does it, but with Python. If in "Scripting" layout this works fine with the following code:

import bpy
override = {}
override['window'] = bpy.context.window
override['scene' ] = bpy.context.scene
override['screen'] = bpy.context.screen
override['area'  ] = bpy.context.screen.areas[2]
override['region'] = bpy.context.screen.areas[2].regions[4]
bpy.ops.view3d.view_all(override, center = True)

But it does not work if the view is in quadview mode; only the view in the lower left corner is aligned then. I tried to replace the region line by

override['region'] = bpy.context.screen.areas[2].space.active.region_quadviews[x]

(x = 0..3) but this fails because the region_quadviews[x] are of type RegionView3D instead of type Region. Is it possible to get four regions of type Region of a quadview?

Strange: Clicking on the menu item shows the same behaviour, i. e. only the lower left view is aligned; but using the shortcut (Shift-C) aligns the view the mousepointer is over - this is my goal.

$\endgroup$
0
$\begingroup$
import bpy
override = {}
override['window'] = bpy.context.window
override['scene' ] = bpy.context.scene
override['screen'] = bpy.context.screen
override['area'  ] = bpy.context.screen.areas[2]

for region in [r for r in bpy.context.screen.areas[2].regions if r.type == 'WINDOW']:
    override['region'] = region
    bpy.ops.view3d.view_all(override, center=True)
| improve this answer | |
$\endgroup$
  • $\begingroup$ Thanks, it works. I combined this solution with this one link and can align the quadview quarter where the mousepointer is over. Perfect. $\endgroup$ – frisee Dec 16 '14 at 9:16
  • $\begingroup$ I want to solve same problem, but for Node Editor. "bpy.ops.node.view_all(override)" is not working $\endgroup$ – Cenda May 5 '18 at 10:34

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.