3
$\begingroup$

I'm trying to determine if an object is a linked duplicate in a script.

My test scene is as simple as possible, 2 cubes, one a linked duplicate of another.

The following I have tried to no avail:

  • bpy.data.objects["Cube.001"].library (returns None)
  • bpy.data.objects["Cube.001"].original (returns "Cube.001")
  • bpy.data.objects["Cube.001"].is_property_set("linked") (fails to run)

I attempted to grep around in the source code to find a solution but I, unfortunately, couldn't find anything that worked.

$\endgroup$
1
  • $\begingroup$ bpy.objects["Foo"].data $\endgroup$
    – batFINGER
    Jul 23, 2020 at 19:33

1 Answer 1

3
$\begingroup$

Object.data

Linked duplicates will have the same linked data, if there is linked data. For an empty ob.data is None

import bpy
from collections import defaultdict

scene = bpy.context.scene

data_links = defaultdict(list)
for ob in scene.objects:
    data_links[ob.data].append(ob)
    
for k, v in data_links.items():
    print(k, v)

Sample output, notice there are 4 objects using the mesh "Cube.001"

<bpy_struct, Mesh("Cube.001")> [bpy.data.objects['Cube'], bpy.data.objects['Cube.001'], bpy.data.objects['Cube.002'], bpy.data.objects['Cube.003']]
<bpy_struct, PointLight("Lamp")> [bpy.data.objects['Lamp']]
<bpy_struct, Camera("Camera")> [bpy.data.objects['Camera']]
None [bpy.data.objects['Empty'], bpy.data.objects['Field']]
$\endgroup$
1
  • $\begingroup$ My first brush with defaultdict. Python is very neat and tidy, sometimes.. :) $\endgroup$
    – Robin Betts
    Jul 24, 2020 at 13:12

You must log in to answer this question.

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