3
$\begingroup$

How can i select all objects by type using python scripting. I am trying to select all empties in my scene.

I tried using bpy.ops.object.select_by_type(type='EMPTY') but thats doesn't work.

$\endgroup$

2 Answers 2

7
$\begingroup$

Blender 2.7x

import bpy

objects = bpy.context.scene.objects

for obj in objects:
    obj.select = obj.type == "EMPTY"

Blender 2.8x

import bpy

objects = bpy.context.scene.objects

for obj in objects:
    obj.select_set(obj.type == "EMPTY")

See this answer for more info.

$\endgroup$
1
  • 2
    $\begingroup$ Nitpick: in the for loop you can just do obj.select = obj.type == "EMPTY" $\endgroup$
    – B.Y.O.B.
    Feb 13, 2018 at 20:06
2
$\begingroup$
item='EMPTY'
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.object.select_by_type(type=item)

where item can take any of the following values according to this documentation:

[‘MESH’, ‘CURVE’, ‘SURFACE’, ‘META’, ‘FONT’, ‘HAIR’, ‘POINTCLOUD’, ‘VOLUME’, ‘GPENCIL’, ‘ARMATURE’, ‘LATTICE’, ‘EMPTY’, ‘LIGHT’, ‘LIGHT_PROBE’, ‘CAMERA’, ‘SPEAKER’]
$\endgroup$
3
  • 2
    $\begingroup$ It's recommended to avoid operators if you can. @doakey3's answer is preferred. $\endgroup$
    – dr. Sybren
    Feb 27, 2018 at 17:35
  • $\begingroup$ Thank you. Is there a reason why? $\endgroup$
    – Amir
    Feb 27, 2018 at 18:31
  • $\begingroup$ Operators are slower, create (possibly unnecessary) undo steps, are harder to integrate with other code, and are more sensitive to the content in which they are used. $\endgroup$
    – dr. Sybren
    Feb 27, 2018 at 20:16

You must log in to answer this question.

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