Measurement 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 graphical interface: when the path is selected, the edit panel contains the PrintLen button. When the button is pressed, the length is displayed on the right.

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

Note. I am not interested in the PathLen value that is in frames, not Blender units.

0


a source to share


1 answer


The best idea I have 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)

      

+1


a source







All Articles