simple question select faces

Hello:) I have a really simple question.
How to select single face using python?

I can use code to vertices.

bpy.data.meshes['Mesh'].vertices[4*n].select=True    bpy.data.meshes['Mesh'].vertices[4*n+1].select=True
    bpy.data.meshes['Mesh'].vertices[4*n+2].select=True
    bpy.data.meshes['Mesh'].vertices[4*n+3].select=True

This not work good when i have faces which has got 3 vertices and faces where are 4 vertices.

Probably I can make that much simpler:)

bpy.data.meshes['Mesh'].faces[1]select=True

Doesn’t work and I do not know why.

Thanks for all answers:)

it’s called polygons now, not faces. make sure the object is not in edit mode, or your selection won’t happen.


bpy.data.meshes['Cube'].polygons[0].select = True
# or, currently selected object, in object mode again
bpy.context.object.data.polygons[0].select = True

when you then check in edit mode, the changes selection will show up.

or use bmesh module to select faces without switching from edit mode!

http://www.blender.org/documentation/blender_python_api_2_64_release/bmesh.html

sorry, but where exactly on this page says how I can select faces using bmesh module? ive checked but i couldn’t find…

it’s the introduction to the bmesh module, if you click “bmesh.types”, you find the methods, e.g. select_set:

http://www.blender.org/documentation/blender_python_api_2_64_release/bmesh.types.html#bmesh.types.BMFace.select_set

import bpy, bmesh

ob = bpy.context.object

if ob.mode == 'EDIT':
    bm = bmesh.from_edit_mesh(ob.data)
    bm.select_mode = {'FACE'}
    bm.faces[0].select_set(True)
    bm.faces[1].select_set(False)
    ob.data.update()

yes, I can manage the flag state with either select_set or .select, I ve seen them being changed over the terminal console.

But it doesn’t get updated on the scene somehow. .select or select_set works only with the python console, but not if it is written inside a script. Only the state of the flag is changed.

Or do I have to do ob.data.update() every time I change the state?