# export the length of edges to a text file from blender.

I am working with blender 2.78, and I want to export the edge lengths of a mesh to a file text, but I don't know how to do it with Blender. I will explain more, I have a bunny wavefront, and I did display the edge length using the Transform panel. Then what I want to know is there a way to export those lengths in a text file for example. I searched on the net and I found that I can use the NeuroMorph Measurement Tools, I did add the tool but it seems that it exports just the area and volume but not what I want.

It is obvious that we can just compute the lengths based on coordinates of vertices and faces stored in the .obj file, and take into account the repetition of edges between tow adjacent faces (the thing that I haven't think about how to implement it yet on Matlab). But if it is possible to get it from blender directly it would be great.

It might be a simple way but I am pretty new with blender and I don't find the way.

You can use this script, tested on happy.ply for performance test (6 seconds on my laptop):

import bpy
import time

#Calc the length between 2 vertices given by vertex index
def CalcLength( obj, vertices ):
v1 = obj.data.vertices[vertices[0]] #Get the first
v2 = obj.data.vertices[vertices[1]] #Get the second
return (v1.co - v2.co).length #Calculate the length from their coordinates

#In object mode
obj = bpy.context.object #selected object
#obj = bpy.data.objects['name'] #or by name

fileName = "c:\\tmp\\exemple.txt" #Your file name

file = open( fileName, 'w+' ) #Open a file (will create or erase an existing one

startTime = time.time()

try:
#Write to the file the length of each edge
file.write( '\n'.join([str(CalcLength(obj, e.vertices)) for e in obj.data.edges] ) )
finally:
file.close()

executionTime = time.time() - startTime
print( executionTime )


Here is the file so you can look at the setting:

• thank you so much for help, it works great. Thank you a lot. – J.Hr Apr 3 '17 at 10:36