0
$\begingroup$

I saw this example of how to select objects by name with a script, I would like to know if anyone knows how to modify it to be able to select all the objects with the subdivision surface modifier.

Thank you very much

# Deselect all objects
bpy.ops.object.select_all(action='DESELECT')

for o in bpy.data.objects:
    # Check for given object names
    if o.name in ("Cube.026","Cube.027","Cube.028"):
        o.select_set(True)
$\endgroup$

1 Answer 1

2
$\begingroup$

First approximation

Gives you a list of objects matching the criteria in the current scene

import bpy

mlist = [xbbb for xbbb in bpy.data.objects if [xxx for xxx in xbbb.modifiers  if 'SUBSURF' == xxx.type and xbbb.name in bpy.context.scene.objects]]

for bbb in mlist:
    bbb.select_set(True)
    print(bbb.name)

mlist = [xbbb for xbbb in bpy.data.objects if [xxx for xxx in xbbb.modifiers if 'SUBSURF' == xxx.type and xbbb.name in bpy.context.scene.objects]]

Please make suitable adjustments. You may need to horizontal scroll to see all above.


More verbose and across all scenes

[xbbb for xbbb in bpy.data.objects if len([xxx for xxx in xbbb.modifiers if 'SUBSURF' == xxx.type])]

Please see Python comprehension list

$\endgroup$

You must log in to answer this question.

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