You actually can achieve this by creating a shape key on each frame with modifiers applied and animating those shape keys:
import bpy
ob = bpy.context
obAc = ob.active_object
mesh_data = obAc.data
start_frame = bpy.context.scene.frame_start
end_frame = bpy.context.scene.frame_end
if not obAc.data.shape_keys:
obAc.shape_key_add(name="Basis")
# Create shape keys for each frame
for frame in range(start_frame, end_frame + 1):
bpy.context.scene.frame_set(frame)
# Evaluate the mesh with modifiers
depsgraph = bpy.context.evaluated_depsgraph_get()
object_eval = obAc.evaluated_get(depsgraph)
mesh_eval = object_eval.data
# Create a new shape key and set its points based on the current frame
shape_key = obAc.shape_key_add(name=str(frame))
# Collect vertex positions for the current frame
vertices = [vertex.co for vertex in mesh_eval.vertices]
# Set shape key data
shape_key.data.foreach_set('co', [c for v in vertices for c in v])
if obAc.data.shape_keys:
shape_keys = obAc.data.shape_keys.key_blocks
# Iterate through shape keys and set keyframes
for frame in range(start_frame, end_frame + 1):
ob.scene.frame_set(frame)
for shape_key in shape_keys:
if shape_key.name.isdigit():
value = 1.0 if int(shape_key.name) == frame else 0.0
shape_key.value = value
shape_key.keyframe_insert(data_path='value', index=-1)