I have a method that iterate through a collection(the assetsHandCollection), copies (link copy) the object to another collection(the gestureCollection) and then it should move the linked object. This is the method:
def make_gestures():
gestureCollection = bpy.data.collections.get("Gesture")
for hand in assetsHandCollection.objects:
linkedCopyHand = hand.copy()
gestureCollection.objects.link(linkedCopyHand)
linkedCopyHand.hide_viewport = False
linkedCopyHand.hide_render = False
linkedCopyHand.hide_select = False
bpy.context.view_layer.objects.active = linkedCopyHand
bpy.ops.transform.translate(value=(50, 0, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
The object are correctly linked to the new collection but they are not moved.
If I replace the line:
bpy.ops.transform.translate(value=(50, 0, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
with
linkedCopyHand.matrix_world.translation += Vector((50, 0,0))
It works, the oject are correctly linked and translated.
If I check in the console which is the last active object after my script finished to run (with bpy.context.view_layer.objects.active), it is, correctly, one of the object that I have just link copied. If the console I try to run the command:
bpy.ops.transform.translate(value=(50, 0, 0), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(True, False, False), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False)
It return CANCELLED, without any further detail.
ob.select_set(True)
to select as well as setting to active, since the op prob works only on selected objects. $\endgroup$