tags:

views:

318

answers:

1

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.

A: 

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()
    mesh.getFromObject(path)

    return sum(edge.length for edge in mesh.edges)
Jon-Eric