Hi, this is a script to easily get a 3D path from an object’s animation.
It’s just like baking the Motion Path. You can then modify the curve and load it again as a constraint, or maybe create a new object…
In C4D you are able to edit the animations as a path, directly in the viewport, and so in AE, well at least the position data… anyway, here’s my noob attempt to do something ‘similar’. It will add a point every frame through the playback range, like the Motion path does. You can change this at the beginning of the script.
import bpy
scene = bpy.context.scene
# step / start / end
paso = 1
inicio = scene.frame_start
fin = scene.frame_end
actual = scene.frame_current
puntos = list(range(inicio - 1, fin, paso))
recorrido = bpy.data.curves.new('recorrido','CURVE')
curva = bpy.data.objects.new('curva',recorrido)
bpy.context.scene.objects.link(curva)
recorrido.dimensions = '3D'
recorrido.use_fill_back = False
recorrido.use_fill_front = False
spline = recorrido.splines.new('BEZIER')
spline.bezier_points.add(len(puntos) - 1)
c = 0
ob = bpy.context.object
for n in puntos:
scene.frame_set(n)
matrix = ob.matrix_world.copy()
nodo = spline.bezier_points[c]
nodo.co = tuple(matrix.translation_part())
nodo.handle_right_type='VECTOR'
nodo.handle_left_type='VECTOR'
c += 1
scene.frame_set(actual)
This is an awesome script, Liero! Thank you so much. It’s still helping people in 2018! A couple suggestions that could be great to expand this script would be the following:
Have the script set the new curve’s origin to be the motion path object’s starting location (on the motion path’s start frame).
The ability to overwrite a previous curve and maintain its name. This would be super useful: first select the object with an active motion path. Then shift-select the curve you want to overwrite. Run the script. The script will delete the old curve, create a new curve from the motion path, and use the name of the old curve.
Thank you so much again for this incredibly useful tool. BTrace, though a great addon, currently will not trace the motion of an object if the motion is generated from a parent object, so your script is still the best solution for my intended usage. https://developer.blender.org/T53912
Here’s an updated 2.8 version:
-works on every selected objects
-generate and kill the motion path (you have nothing to do before launching the script)
-generate a curve named based on the source object name + “_Path”
-based on the scene start and end frame
import bpy
scene = bpy.context.scene
start = scene.frame_start
end = scene.frame_end
sel = bpy.context.selected_objects
for ob in sel:
#ob = bpy.context.object
bpy.ops.object.paths_calculate(start_frame=start, end_frame=end)
mp = ob.motion_path
if mp:
path = bpy.data.curves.new('path','CURVE')
curve = bpy.data.objects.new('Curve',path)
curve.name = ob.name+"_Path"
bpy.context.scene.collection.objects.link(curve)
path.dimensions = '3D'
spline = path.splines.new('BEZIER')
spline.bezier_points.add(len(mp.points)-1)
for x in range(len(mp.points)):
o = spline.bezier_points[x]
o.co = mp.points[x].co
o.handle_right_type = 'AUTO'
o.handle_left_type = 'AUTO'
bpy.ops.object.paths_clear()