Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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 ?

share|improve this question

3 Answers 3

up vote 3 down vote accepted

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.

share|improve this answer
    
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. –  tigrou Mar 23 '13 at 15:48
1  
Here's blender python api for 2.66a: blender.org/documentation/blender_python_api_2_66a_release –  sarahm Mar 23 '13 at 15:51

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)
share|improve this answer
    
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. –  ktodisco Dec 13 '13 at 19:56
    
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. –  sambler Dec 14 '13 at 1:46

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)
share|improve this answer
    
This isn't an answer. You should edit the original question to add any extra info. –  petervaz Mar 27 '13 at 1:22

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.