I'm trying to select objects that meets certain criteria in this case their dimension (not the scale) but I'm unable to figure out the proper way to make it work.
I have a over simplistic script which doesn't work although the context is the right one in the python console.
import bpy
for obj in bpy.context.scene.objects:
if bpy.context.object.dimensions[2] = 2.0:
obj.select_set(True)
Here is the final working code following the suggestions:
import bpy
from math import isclose
scene = bpy.context.scene
for obj in scene.objects:
x = obj.dimensions[0]
y = obj.dimensions[1]
z = obj.dimensions[2]
if obj.type == 'MESH':
if (isclose(y, 2.1, rel_tol=1e-3)):
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
else:
obj.select_set(False)