5
$\begingroup$

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?

$\endgroup$
6
$\begingroup$

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)
$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – Omar Emara Nov 6 '14 at 16:42

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.