1
$\begingroup$
#I have cup shaped object that starts with a circle that is extruded and scaled
# I need to select all faces in edit mode to UV unwrap faces(Right click)
# I cannot select all faces. Please help

# Does not work
so = bpy.context.active_object
bpy.context.view_layer.objects.active = so
bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type='FACE')
bpy.ops.mesh.select_all(action='TOGGLE')
bpy.ops.uv.cube_project(cube_size=10)



# Works only in VERT mode
mesh = so.data
bm=bmesh.from_edit_mesh(mesh)

bpy.ops.mesh.select_mode(type='VERT')
vtest = False  ##see if we can select side of active
for vert in bm.verts:
    vert.select = True
$\endgroup$
1
$\begingroup$

Your first example isn't working because you are toggling the selection rather than setting it. change

bpy.ops.mesh.select_all(action='TOGGLE')

to

bpy.ops.mesh.select_all(action='SELECT')

for it to actually select all the faces. Also, you don't need the second line, so your first example could be as simple as

bpy.ops.object.mode_set(mode='EDIT')
bpy.ops.mesh.select_mode(type='FACE')
bpy.ops.mesh.select_all(action='SELECT')
bpy.ops.uv.cube_project(cube_size=10)

If you want to use bmesh to select faces then you need to do something like this

object = bpy.context.object
bm = bmesh.from_edit_mesh(object.data)
faces = bm.faces
bm.faces.ensure_lookup_table()

for face in bm.faces:
    face.select = True

bmesh.update_edit_mesh(object.data)

bpy.ops.uv.cube_project(cube_size=10)

Note that the above code assumes that the selected object is a mesh object and is in edit mode. You should add code to ensure that such things are so.

$\endgroup$
1
  • $\begingroup$ Your fix worked. Thanks a ton for the fast reply. Beginner's blues. $\endgroup$
    – lmwald
    Dec 2 '21 at 8:29

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.