Select similar objects by number of vertices?

Does a script or add-on exist that can select objects based on number of vertices in the selected object? I’ve got a snippet that does volume but it fails on flat objects. My scene is made up of many leaves and flower parts all sharing the same material.

All my searching turns up solutions for edit mode, on the same object. I’m looking for something that will work in object mode.

Do you really need to go to edit mode?
You can see how many vertices an object has by:

len(bpy.data.objects[‘Your_Object’].data.vertices)

then is just a matter of comparing it between objects.

I’d like to avoid edit mode.

Since I have lots of objects I need to organize I was looking for something to save lots and lots of clicking to select different objects. For example, all leaves have 5 or 6 vertices, but they’re different scales/sizes so area wouldn’t work so well.

you can get the area in object mode…

area = sum([poly.area for poly in bpy.data.objects[‘Your_Object’].data.polygons])

:wink:

Is it possible to select objects that have N number of vertices?

This should work off of active object.

import bpy


active_object = bpy.context.active_object
active_verts = len(active_object.data.vertices)


for all_objects in bpy.context.scene.objects:
    if all_objects.type == 'MESH':
        all_objects_verts = len(all_objects.data.vertices)           
        if all_objects_verts == active_verts:
            all_objects.select = True
1 Like

That’s perfect, thanks!

Can you please update this one for 2.8? Thanks

1 Like

Thanks! I was sure I missed it.

Updated for 2.80:

import bpy

active_object = bpy.context.view_layer.objects.active
active_verts = len(active_object.data.vertices)

for all_objects in  bpy.context.view_layer.objects:
    if all_objects.type == 'MESH':
        all_objects_verts = len(all_objects.data.vertices)           
        if all_objects_verts == active_verts:
            all_objects.select_set(state = True)```
1 Like