Select / or delete small objects (dimension > ...) - script

Hello,

how can I select objects that have a smaller dimension X value then 0.02 or so!?

I only found the py.ops.object.select_pattern(pattern=“Name”), but how can I select or delete by dimension !?

THANXS :wink:

You’re going to need a little bit more advanced scripting for that. The bpy.ops functions are rather limited in their scope.

This code steps through each object in the scene and compares the x dimension to a fixed value, selecting the smallest objects:

import bpy

for i in bpy.data.objects:
    if i.dimensions.x < .02:
        i.select = True

Here’s something for just mesh objects. Remove last line not to delete.

import bpy


scene = bpy.context.scene

for ob in scene.objects:
    x = ob.dimensions[0]    
    y = ob.dimensions[1]
    z = ob.dimensions[2]
            
    if ob.type == 'MESH':
        if x < 0.02:
            ob.select = True
        else: 
            ob.select = False

bpy.ops.object.delete()

:yes: python rocks

Hello,
I know this thread is old, but I just tried this simple code in Blender 2.92, and it throws a syntax error in line 4 (invalid syntax).
location: < unknown location > : -1

What can I do?

Looks like they changed how to select an object via python data at some point in the last 4 years, this code is working presently:

import bpy

for i in bpy.data.objects:
    if i.dimensions.x < .02:
        i.select_set(True)
1 Like

Yes, this one is working fine in Blender 2.92 :smiley:
Thanks a lot for your help ^^

1 Like

Hmm, maybe a bit basic. If someone likes it more comfortable:

https://github.com/filippocastelli/SelectByVolume

I tried to install the SelectByVolume add-on in Blender 2.80 (32bit) environment, but I could not install the latest SelectByVolume-0.2.3 or the oldest SelectByVolume-0.0.1.