# how to get number of selected vertex and the number of total vertex with python?

how to get number of selected vertex and the number of total vertex with python? and how can I select an object by its name and make it the active?

You have multiple questions there:

import bpy
import bmesh

obj = bpy.context.active_object
if bpy.context.mode == 'EDIT_MESH':
bm = bmesh.from_edit_mesh(obj.data)
verts = [ v.index for v in bm.verts if v.select ]
else:
verts = [ v.index for v in obj.data.vertices if v.select ]

print(verts)
print(len(obj.data.vertices))


and for the second question:

bpy.context.scene.objects.active = bpy.data.objects[name]
# fix shortcoming identified by Omar :
for obj in bpy.context.scene.objects:
obj.select = ( obj == bpy.context.scene.objects.active)

• thanks,the 1st one work fine but the 2nd one is not working well,I want it to select the object only but I find that it select 2 objects the one that was active and the one I select by the script – Omar Emara Nov 6 '14 at 16:42