3
$\begingroup$

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

enter image description here

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().

$\endgroup$

2 Answers 2

6
$\begingroup$

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":
$\endgroup$
6
$\begingroup$

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'
$\endgroup$
1
  • 1
    $\begingroup$ Good to know. Nice, thanks. ^^ $\endgroup$ Jun 12, 2021 at 9:28

You must log in to answer this question.

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