DeltaFreeze blender

i’m making a delta freeze

It freezes the selected obj, but when you run this, everything returns to its original state.

I want to do delta freeze while maintaining shape

import bpy

for x in bpy.context.selected_objects:

x.location[0] = x.delta_location[0]
x.location[1] = x.delta_location[1]
x.location[2] = x.delta_location[2]



x.rotation_euler[0] = x.delta_rotation_euler[0]
x.rotation_euler[1] = x.delta_rotation_euler[1]
x.rotation_euler[2] = x.delta_rotation_euler[2]


x.scale[0] = x.delta_scale[0]
x.scale[1] = x.delta_scale[1]
x.scale[2] = x.delta_scale[2]



x.delta_location[0] = 0
x.delta_location[1] = 0
x.delta_location[2] = 0


x.delta_rotation_euler[0] = 0
x.delta_rotation_euler[1] = 0
x.delta_rotation_euler[2] = 0


x.delta_scale[0] = 1
x.delta_scale[1] = 1
x.delta_scale[2] = 1


bpy.ops.object.transform_apply(location=True, rotation=True, scale=True)