Python – Measure Path Length in Blender Script


In Blender (v2.48), how can I determine the length of a path (in Blender units) from a Python script?

The value is available from the GUI: With the path selected, the Editing panel contains a PrintLen button. The length appears to the right when the button is pressed.

How can I obtain this value programmatically from a Python script running in Blender?

Note: I'm not interested in the PathLen value which is in frames, not Blender units.

Best Solution

The best idea I've found is to create a mesh from the path and sum the length of the segments (edges).

import Blender

def get_length(path):
    Return the length (in Blender distance units) of the path.
    mesh = Blender.Mesh.New()

    return sum(edge.length for edge in mesh.edges)