0
$\begingroup$

I can't seem to link animation data programmatically. I have tried:

bpy.data.objects["Object_1"].select_set(True)
bpy.data.objects["Object_2"].select_set(True)
bpy.ops.objects.make_links_data(type='ANIMATION')

When I run this script I get the following:

AttributeError: Calling operator "bpy.ops.objects.make_links_data" error, could not be found

I am not too sure if it is because the second selection should be a shift + mouse click and this isn't reflected in the code (I can't seem to find an option to shift click an object in python) or my script isn't correct.

Would appreciate any help, Thanks in advance!

$\endgroup$
0

1 Answer 1

1
$\begingroup$

Make sure you have the right name

The operator is bpy.ops.object.make_links_data() note it's object not plural.

The error.

>>> bpy.ops.objects.make_links_data()
Traceback (most recent call last):
  File "<blender_console>", line 1, in <module>
  File "/home/batfinger/blender-git/xxx/bin/2.91/scripts/modules/bpy/ops.py", line 202, in __call__
    ret = op_call(self.idname_py(), None, kw)
AttributeError: Calling operator "bpy.ops.objects.make_links_data" error, could not be found

No error.

>>> bpy.ops.object.make_links_data(type='ANIMATION')
{'FINISHED'}

The active object is the source the other selected objects the targets.

Set active object with python.

To sum up, to make links from "Cube" to cones "Cone", "Cone.001", "Cone.002" would

obj = context.scene.objects.get("Cube") 
if obj:
    context.view_layer.objects.active = obj
    for o in ("Cone", "Cone.001", "Cone.002"):
        o.select_set(True)

    bpy.ops.object.make_links_data(type='ANIMATION')
$\endgroup$

You must log in to answer this question.

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