How to obtain the number of selected vertices in a mesh...

Scripting in Blender with Python, and working on the API

Moderators: jesterKing, stiv

Post Reply
dvochin
Posts: 0
Joined: Mon Aug 20, 2012 9:39 pm

How to obtain the number of selected vertices in a mesh...

Post by dvochin »

Is there a way to quickly do that without being forced to iterate through the verts and checking their 'select' flag?

CoDEmanX
Posts: 0
Joined: Sun Apr 05, 2009 7:42 pm
Location: Germany

Post by CoDEmanX »

no there isn't, see http://wiki.blender.org/index.php/Dev:2 ... esign_TODO
convenience function to get selected verts/edges/faces to prevent expensive iteration over meshes. Something like: me.verts.selected
for a quick check without leaving editmode you could do:

Code: Select all

ob = bpy.context.object
ob.update_from_editmode() # not available in older versions!
verts_sel = len([v for v in ob.data.vertices if v.select])
Note: this requires blender 2.67+
I'm sitting, waiting, wishing, building Blender in superstition...

dvochin
Posts: 0
Joined: Mon Aug 20, 2012 9:39 pm

Post by dvochin »

Many thanks CodeManX, that will do the job! Didn't know about updating from edit mode either... useful!

Post Reply