2
$\begingroup$

I am trying to select all objects with a custom property with a given value but with no success. The custom property is "category" and the value is "Windows". This is what I have tried. Any ideas?

    for obj in bpy.context.visible_objects:
        if bpy.data.objects[str(obj.name)]["category"]=="Windows":      
            obj.select_set(True)

There might also be variants of "Windows" so wildcards would be useful.

$\endgroup$
1
  • $\begingroup$ If you want to setup custom lookup rules for the property names I suggest you look up regex (regular expressions) they're daunting at first but really powerful. $\endgroup$
    – Gorgious
    Commented Jul 24, 2022 at 6:14

1 Answer 1

3
$\begingroup$
for obj in bpy.context.visible_objects:
    if "category" in obj:
        if obj["category"] == "Windows":      
            obj.select_set(True)
$\endgroup$
1
  • $\begingroup$ If you allocate a custom property to bpy.types.object then every object will have that property and your first if will always return True. $\endgroup$ Commented Jul 25, 2022 at 22:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .