Length of a Bezier curve in 2.5?


if bpy.context.active_object.type == "CURVE":
   curveob = bpy.context.active_object
   print(curvob.data.splines[0].type)


will return BEZIER,POLY or NURBS

fingers crossed this posts… looks like the db server is a strugglin…

the script is for blender-2.56
and it does not use the resolution of the BezierCurve blender-object.
It uses a fixed one, set to only 3. You can check the diff. if you change
the resoultion of the BezierCurve inside blender.
I have a newer version with cubic-bezier-interpolation. At the moment i try
to understand those things about creation of “knot”-points for the bsplines.
I will not make a gui for it - because i hope that it might be possible to
use the internal c-routines. Like said, there is already a bezier-calculation in
mathutils (it uses too a blender-internal-c-routine), but a general api-function
is still missing. And i dont know all meanings about the
blender-Bezier/BSplin-Curve settings.

:smiley: Many, many thanks Leiro and BatFinger for working it out! I am now even more tempted to get into Python, especially with the BlenderCookie tutorials to help too…

As a technical aside: sadly, that’s mathematically impossible, as there is no general closed form for the formula that needs to be computed to get the arc length for a cubic bezier curve. For some curves, the formula can be simplified because certain values for c1/c2/c3/c4 coordinates cancel each other out, but for any “complicated” bezier curve the arc length can only be approximated, not directly computed based on the curve’s parameters.

directly may be not but you can make copy transform into a poly then you can calculate lenght
ok not very elegant but shoudl give good result

i wish it was that easy when doing that with an ellipse
which i’m still trying to find out how and with high precision!
if you have any idea let me know !

happy 2.5

Could this possible be the post you guys are looking for? – http://blenderartists.org/forum/showthread.php?t=196533 – about computing curve length in 2.49?

no we are in 2.5
2.49 does not exist forget about it !

happy 2.5

Ricky – from your own quote <<but i tough there was a way in 2.49 to use the values from the Curve itself to calculate the lenght of curves!>> But wait: 2.49 doesn’t exist, so there’s no way to calculate it is there?

Ya try to be helpful, and get 'tude in return…

very nice code! I need a code to say the sum of the lengths in a mesh (those who appears when we get in the edit mode). is that so hard to do? Thanx!

Does it still work?
Nothing happens to me here by running it…

I’m running this code and when I hit “Calculate” with the curve selected, it outputs the length, but it deletes the selected curve. How can this be avoided?

import bpy, mathutils
from mathutils import Vector
le = '-----------'


class PANEL(bpy.types.Panel):
    bl_label = "Curve Length"
    bl_space_type = "VIEW_3D"
    bl_region_type = "UI"
    def draw(self, context):
        layout = self.layout
        layout.operator("boton.le")
        box = layout.box()
        box.label(text="Length: " + str(le))
   
class BOTON(bpy.types.Operator):
    bl_idname = "boton.le"
    bl_label = "Calculate"
    def execute(self, context):
        ob = context.active_object
        if ob and ob.select and ob.type == 'CURVE':
            em = (ob.mode == 'EDIT')
            bpy.ops.object.mode_set()
            bpy.ops.object.convert(target='MESH', keep_original=False)
            ve = ob.data.vertices
            global le
            dd = le = 0
            for i in ob.data.edges:
                dd = ve[i.vertices[0]].co - ve[i.vertices[1]].co
                le += dd.length
            le = round(le,4)
            bpy.ops.ed.undo()
            if em: bpy.ops.object.mode_set(mode='EDIT', toggle=False)
        else:
            le = 'not a curve object'
        return{'FINISHED'}
    
bpy.utils.register_class(PANEL)
bpy.utils.register_class(BOTON)

Hi everyone, I’ve worked at trying to get my head around Python and Blender’s API, and here is the result. I altered liero’s code to get it working again, because his original code just wasn’t working the way I wanted it. There was also a problem where the script wouldn’t change the output length even if the scale of the curve was increased. The code now works as an addon - just place it into the addon folder.

I credit liero as the author, since it’s all basically his code.

Here is the addon file

What kind of object do you need to have in your scene to bring up object get path length ( the curve length panel)?

I had to reload the script thru the text panel. I checked register b4 I loaded the script. I don’t no if clicking register helped.

Any chance the script for this could be updated so that it would be possible to copy and paste the output? Or perhaps use it as a data path?

I find this script quite useful for calculating wheel rotation in animation of all things. (Transforms have their shortcomings in this regard. It’s a shame the ability to get curve length isn’t a built-in feature.) I’d post a test thread showing some basic animation, but I’m still too new to the forums right now.