5
\$\begingroup\$

I have created a bezier curve in Blender.

enter image description here

I'd like to export this curve to a text file. What I need is :

Control point + handles, three points in total.

Example :

{{ 2.3333,4.3942, 55.333 }, { 0.3234, 2.4234, 4.0332 }, { 2.534, 6.S234, 12.0332 }}

I have tried to export the scene in Collada format but it doesn't seems to include curves information.

What is the easiest / simplest way to export this curve to some readable text file format ?

\$\endgroup\$
1
  • \$\begingroup\$ can anyone say why doesn't the exported Collada file include curves? \$\endgroup\$
    – Dor
    Nov 14, 2015 at 17:16

3 Answers 3

3
\$\begingroup\$

There are scripts available that do this. Though they may be a bit out of date. Perhaps not the simplest method, but you can write your own python script to export them. Using Blender scripting you can enumerate the objects in the scene and then enumerate through all the curves of a particular bezier curve.

\$\endgroup\$
2
  • \$\begingroup\$ Thanks. Most of the scripts i have found (including the one you suggest) are for old version of Blender (2.4?). It seems they changed almost all the api since recent 2.6 versions (the one i use). Even documentation for 2.6 still do not exists : wiki.blender.org/index.php/Doc:2.6/Tutorials/Extensions/Python/…. Do you recommand sticking with old version ? I was expecting some Blender script guru to show me a simple script example to start with. eg: how to loop on control points of a curve. \$\endgroup\$
    – tigrou
    Mar 23, 2013 at 15:48
  • 1
    \$\begingroup\$ Here's blender python api for 2.66a: blender.org/documentation/blender_python_api_2_66a_release \$\endgroup\$
    – Exilyth
    Mar 23, 2013 at 15:51
4
\$\begingroup\$

Try this:

import bpy
myCurve = bpy.data.curves[0] # here your curve
spline= myCurve.splines[0] # maybe you need a loop if more than 1 spline

print("\n======================")
for x in range(len(spline.bezier_points)):
    print("Point " + str(x)
        ,spline.bezier_points[x].co
        ,spline.bezier_points[x].handle_left
        ,spline.bezier_points[x].handle_right)
\$\endgroup\$
2
  • \$\begingroup\$ How would one integrate this Python script into Blender in order to utilize it? This seems like the start of a good answer but it could be expanded upon. \$\endgroup\$ Dec 13, 2013 at 19:56
  • \$\begingroup\$ blender incorporates and depends on python to run. You can paste this code into a text window and run it as a script. The top of the blender window most likely lists default as the current layout, change that to scripting to see a layout with 3dview, text and python console visible. \$\endgroup\$
    – sambler
    Dec 14, 2013 at 1:46
0
\$\begingroup\$

For anyone interested, here is revelant code :

ob = bpy.context.object # active object 

# iterate over points of the curve's first spline 
file = open('foo.txt', 'w')     
for p in ob.data.splines.active.bezier_points: 
    file.write("%.3f, %.3f, %.3f" % p.co.x, p.co.y, p.co.z) 
    file.write("%.3f, %.3f, %.3f" % p.handle_left.x, p.handle_left.y, p.handle_left.z) 
    file.write("%.3f, %.3f, %.3f" % p.handle_right.x, p.handle_right.y,p.handle_right.z) 
fclose(f)
\$\endgroup\$
1
  • \$\begingroup\$ This isn't an answer. You should edit the original question to add any extra info. \$\endgroup\$
    – petervaz
    Mar 27, 2013 at 1:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .