Convert object motion path to curve

Hi Guys,

We are animating a simple ball flying all over the place. We would then like to take the motion path of the ball and convert it to a curve to create some solid geometry like trails. Is there a way to create a curve from the motion path of an object? Thanks.

1 Like

here’s an old script… select object and calculate motion path, then run script from a text editor


## path from -calculated- motion path

import bpy
ob = bpy.context.object
mp = ob.motion_path

if mp:
    path = bpy.data.curves.new('path','CURVE')
    curve = bpy.data.objects.new('Curve',path)
    bpy.context.scene.objects.link(curve)
    path.dimensions = '3D'
    spline = path.splines.new('BEZIER')
    spline.bezier_points.add(len(mp.points)-1)
    
    for i,o in enumerate(spline.bezier_points):
        o.co = mp.points[i].co
        o.handle_right_type = 'AUTO'
        o.handle_left_type = 'AUTO'

That was awesome. Thank you very much for the help. If you ever stop by New Jersey, I owe you a beer.

You have posted your question in the wrong section.

Yeah, I just realized that. Sorry, can the mod move it for me?

Yes, just ask one to do so.

WORKING VERY WELL ON blender 2.78 (blender of 2016) thanks for the wonderful code :slight_smile:

I am using Blender 2.91 -

Traceback (most recent call last):
File “WizardGhost\Text”, line 11, in
AttributeError: ‘bpy_prop_collection’ object has no attribute ‘link’
Error: Python script failed, check the message in the system console

it should be a simple fix, add ‘collection’ to that line, like …context.scene.collection.objects…

## path from -calculated- motion path

import bpy
ob = bpy.context.object
mp = ob.motion_path

if mp:
    path = bpy.data.curves.new('path','CURVE')
    curve = bpy.data.objects.new('Curve',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 i,o in enumerate(spline.bezier_points):
        o.co = mp.points[i].co
        o.handle_right_type = 'AUTO'
        o.handle_left_type = 'AUTO'

hope it helps

3 Likes

hello. I have so little expirience in coding. Can anybody exolain - how it use to?

well, first your object should be animated, so you can go to object properties panel > motion path > calculate
then make a new ‘text editor’ window, create a new text and paste the script there… or use scripting worspace
now, with your object selected, run script from text editor window and it should generate a curve object…

thank you!