I've been trying to make a small python script that among other things project unwraps UVs using a specific axis and projection type and it fails to project the UVs at the 3D View's manipulated camera angle.
Every time I have tried to use bpy.ops.view3d.view_axis
to manipulate the 3D View's camera and get a UV unwrap at a specific angle all I get is the angle from where the camera was before the script executed, not the camera changes I made in the script
I have tried different ways to substitute contexts and other weird things to see if there's a bug but no dice.
Here's what I have so far, any thoughts would be greatly appreciated:
import bpy
context = bpy.context
object = context.active_object
prev_region = bpy.context.area.type
bpy.context.area.type = 'VIEW_3D'
prev_perspective = bpy.context.space_data.region_3d.view_perspective
if bpy.context.space_data.region_3d.view_perspective == 'PERSP':
bpy.ops.view3d.view_persportho()
# https://blender.stackexchange.com/questions/15118/how-do-i-override-context-for-bpy-ops-mesh-loopcut
win = bpy.context.window
scr = win.screen
areas3d = [bpy.context.area]
region = [region for region in areas3d[0].regions if region.type == 'WINDOW']
override = {'window':win,
'screen':scr,
'area' :areas3d[0],
'region':region[0],
'scene' :bpy.context.scene,
'space' :areas3d[0].spaces[0],
}
bpy.ops.wm.toolbar(override)
print(override['window'])
print(override['area'].type)
print(override['region'].type)
bpy.ops.object.mode_set(override, mode='EDIT')
bpy.ops.mesh.select_all(override, action='SELECT')
bpy.ops.mesh.uv_texture_add(override)
object.data.uv_layers[0].name = 'Color Spread'
object.data.uv_layers[0].active_render = True
object.data.uv_layers[0].active = True
# The Problem
#-----------------------------------
# Changing the view_axis won't change the view when using
# bpy.ops.uv.project_from_view() even though the 3D view
# has been changed.
bpy.ops.view3d.view_selected(override)
bpy.ops.view3d.view_axis(override, type='TOP')
# Failures so far
#-----------------------------------
# Setting view axis multiple times
# Setting projection and view axis multiple times
# AGGRESSIVELY SETTING OVERRIDES FOR EVERYTHING
# Using an Override with as many details as possible
# Only having one 3D View Active
bpy.ops.uv.project_from_view(override, correct_aspect=True,
clip_to_bounds=True, scale_to_bounds=True)
```