# Check whether an object is a reference image

In python, how to check whether an object is a reference image?

This line work only for checking empty-type :-

if obj.data is None :


Unfortunately, it is false for reference image.
I need to this condition to filter out invalid objects for join().

You can use empty_display_type :

>>> print(bpy.data.objects["Empty"].empty_display_type)
IMAGE


So your test would look like :

if obj.empty_display_type == "IMAGE":


Look at the object type.

@thibsert has answered the question at hand, Given

I need to this condition to filter out invalid objects for join().

feel this is somewhat of an XY Problem

If you are joining objects, suggest looking at the Object.type property, since can only join objects of the same type. For example sake let's assume you are joining mesh objects.

All selected mesh objects

mesh_obs = [o for o in context.selected_objects if o.type == 'MESH']


ie only interested in meshes, or to filter out non meshes

if ob.type != 'MESH':
# continue


Similarly all empties in scene, regardless of empty display type

empties = [o of o in context.scene.objects if o.type == 'EMPTY']


ie as demonstrated ob.data is None is not a sufficient test for empties since the advent of reference images. Testing for obj.empty_display_type without knowing the object is an empty will throw an error. Hence a robust test for ref image object is

obj.type == 'EMPTY' and obj.empty_display_type == 'IMAGE'

• Good to know. Nice, thanks. ^^ Jun 12 at 9:28