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$
5
$\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 '18 at 20:06
0
$\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’, ‘ARMATURE’, ‘LATTICE’, ‘EMPTY’, ‘CAMERA’, ‘LAMP’, ‘SPEAKER’]
$\endgroup$
3
  • 1
    $\begingroup$ It's recommended to avoid operators if you can. @doakey3's answer is preferred. $\endgroup$
    – dr. Sybren
    Feb 27 '18 at 17:35
  • $\begingroup$ Thank you. Is there a reason why? $\endgroup$
    – Amir
    Feb 27 '18 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 '18 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.