# Create still copies of a moving object (using python scripting)

I have an object A that is constrained to move on a path and I want to create still copies of it while it moves on the path. I tried the following code but it failed. In particular, it arbitrarily moves the object A itself and all the copies go crazy. Could you please help me fix this? Thank you!

A = context.active_object

for i in range(1, copies_number+1):

A.constraints["Follow Path"].offset_factor = (i-1) / (self.copies_number-1)

copy = duplicate(A) #this is a function that I have introduce to duplicate objects

bpy.context.view_layer.objects.active = copy

bpy.ops.object.visual_transform_apply()

for constraint in copy.constraints:

copy.constraints.remove(constraint)


Without operators

Here is an example of doing this without operators.

• Have the constrained object as active
• Create a copy, strip the follow path constraints from it.
• Create all the copies needed from the copy
• Loop thru the copies,
• calculate the frame,

• set and keyframe offset based on frame

• change to that frame

• give the copy the same matrix world as original at that frame

Test script:

import bpy

N = 10 # number of copies

context = bpy.context
ob = context.object
scene = context.scene
collection = context.collection

copy = ob.copy()
cons = [c for c in copy.constraints if c.type == 'FOLLOW_PATH']
while cons:
copy.constraints.remove(cons.pop())
copies = [copy.copy() for i in range(N - 1)]
copies.append(copy)

frames = 250
for i, copy in enumerate(copies):
f = i * frames / N
# find constraint properly 0 for example sake
ob.constraints[0].offset_factor = f / frames
ob.constraints[0].keyframe_insert("offset_factor", frame=f)

scene.frame_set(f)
copy.matrix_world = ob.matrix_world