thomascheng
(Thomas Cheng)
November 23, 2016, 12:48pm
1
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
liero
(liero)
November 23, 2016, 5:40pm
2
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'
4 Likes
That was awesome. Thank you very much for the help. If you ever stop by New Jersey, I owe you a beer.
XeroShadow
(XeroShadow)
November 24, 2016, 10:16am
4
You have posted your question in the wrong section.
Yeah, I just realized that. Sorry, can the mod move it for me?
XeroShadow
(XeroShadow)
November 29, 2016, 3:50pm
6
Yes, just ask one to do so.
Rene_Meng
(Rene Meng)
September 2, 2020, 10:13pm
7
WORKING VERY WELL ON blender 2.78 (blender of 2016) thanks for the wonderful code
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
liero
(liero)
March 1, 2021, 6:47pm
9
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
8 Likes
hello. I have so little expirience in coding. Can anybody exolain - how it use to?
1 Like
liero
(liero)
October 3, 2021, 2:29pm
11
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…
2 Likes
Topeich
(Ignasi Vidal)
July 15, 2022, 1:08pm
13
Excelent Script!
Thanks for sharing it
Hello, I`m using Blender 3.4 and get such errors in cycle:
for i,o in enumerate(spline.bezier_points):
File “<blender_console>”, line 1
for i,o in enumerate(spline.bezier_points):
IndentationError: unexpected indent
o.co = mp.points[i].co
File “<blender_console>”, line 1
o.co = mp.points[i].co
IndentationError: unexpected indent
o.handle_right_type = 'AUTO'
File “<blender_console>”, line 1
o.handle_right_type = ‘AUTO’
IndentationError: unexpected indent
o.handle_left_type = 'AUTO'
Works in Blender 4.0.2. Thank you!
1 Like