I have an object with several faces, and I want to loop over the faces, adjust the view for each differently and then UV unwrap the face from the chosen view.
I managed to do it using Blender GUI but how can I automate it via a python script?
This is the code I was trying with... I keep getting either a context error or an error saying that BMFace has been removed :s
import bpy, bmesh
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_all(action='DESELECT')
bm = bmesh.from_edit_mesh(bpy.data.objects['my_obj'].data)
for face in bm.faces:
face.select = True
if [...] : # Condition chosen to know which face this is
q = Quaternion([...]) # Set desired corresponding view for this face
for area in bpy.context.screen.areas:
if area.type == 'VIEW_3D':
break
for region in area.regions:
if region.type == 'WINDOW':
break
space = area.spaces[0]
context = bpy.context.copy()
context['area'] = area
context['region'] = region
context['space_data'] = space
r3d = space.region_3d
r3d.view_perspective = 'ORTHO'
r3d.view_rotation = q
for window in bpy.context.window_manager.windows:
screen = window.screen
for area in screen.areas:
if area.type == 'VIEW_3D':
for space in area.spaces:
if space.type == 'VIEW_3D':
for region in area.regions:
if region.type == 'WINDOW':
override = {'window': window, 'screen': screen, 'area': area, 'region': region}
bpy.ops.uv.project_from_view(override, orthographic=False, correct_aspect=True, clip_to_bounds=False, scale_to_bounds=True)
face.select = False
Please help!