I am writing a Python script for Blender 2.8 in which I replace objects in the scene with new objects. I start by importing the new object as a .FBX and linking the original object data to the new object. The new object then needs to be scaled down to fit where the old objects were.
The issue is that when I run the script it appears to have worked until I change the animation frame and the scaling I have applied is erased. Here is a snippet of the code
import bpy
file = '\\Fruit&Veg\\Banana_FBX\\Banana.FBX'
i = file.rfind('\\')
new_asset_name = file[i + 1:-4]
bpy.ops.import_scene.fbx(filepath=file)
bpy.context.view_layer.objects.active = bpy.data.objects[new_asset_name]
bpy.ops.object.scale_clear()
bpy.data.object['Orange'].select_set(True)
bpy.ops.object.make_links_data(type='OBDATA')
bpy.context.view_layer.objects.active = obj
ratio = bpy.data.objects[new_asset_name].dimensions[2] / 0.255 # how much larger new object is
bpy.ops.transform.resize(value=(1/ratio,1/ratio, 1/ratio), orient_type='GLOBAL', orient_matrix=((1, 0, 0), (0, 1, 0), (0, 0, 1)), orient_matrix_type='GLOBAL', constraint_axis=(False, False, True), mirror=True, use_proportional_edit=False, proportional_edit_falloff='SMOOTH', proportional_size=1, use_proportional_connected=False, use_proportional_projected=False, release_confirm=True)