import bpy # USER VARS _____________________________________________________________________ NumberOfObjects = 305 MyObjectName="camera" MyAnimatedCameraName = "MyAnimatedCamera" #SELECT CAMERA __________________________________________________________________ MyAnimatedCamera_ob = bpy.context.scene.objects[MyAnimatedCameraName] # Get the object bpy.context.view_layer.objects.active = MyAnimatedCamera_ob # Make it active object MyAnimatedCamera_ob.select_set(True) #LOOP FOR SELECT CAMERAS __________________________________________________________________ bpy.ops.object.select_all(action='DESELECT') # Deselect all objects # FRAMES bpy.ops.screen.frame_jump(end=False) # Loop for object for i in range(1,NumberOfObjects): #Format name of object MyStr=MyObjectName+str(i) #Select object ob = bpy.context.scene.objects[MyStr] # Get the object bpy.context.scene.frame_set(i) #Get translation and rotation of curent object ploc = ob.location xpos = ploc[0] ypos = ploc[1] zpos = ploc[2] prot = ob.rotation_euler xrot = prot[0] yrot = prot[1] zrot = prot[2] #Set translation and rotation of Camera MyAnimatedCamera_ob.location = (xpos, ypos, zpos) MyAnimatedCamera_ob.rotation_euler = (xrot, yrot, zrot) #Set frame MyAnimatedCamera_ob.keyframe_insert(data_path="location", index=-1) MyAnimatedCamera_ob.keyframe_insert("rotation_euler") #Select camera bpy.context.view_layer.objects.active = MyAnimatedCamera_ob # Make it active object MyAnimatedCamera_ob.select_set(True)