0

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.

Jon-Eric
  • 16,977
  • 9
  • 65
  • 97

1 Answers1

2

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
  • 16,977
  • 9
  • 65
  • 97