The length of edges (in a loop)

Hallo there…i’m a newbie in Python. I need help. :slight_smile:
I made a new method that will be return a total length of edges in a loop. the method looks like this :


def getCurrentLengthOf(name): 
obj_mesh =['nameOfObject'] 
# Store the mesh 
mesh = 
#BMESH import bmesh 
bm = 
#set active the object = obj_mesh 
#set to edit mode 
#set mesh mode into edge mode (vertex, edge, face) 
bpy.context.tool_settings.mesh_select_mode = (False, True, False) 
#set to the object mode first 
index = 0 
if name==some1: 
index = 24218 
elif name==some2: 
index = 20856  
#get an edge by index[index].select=True 
#back to edit mode 
#make a loop from selected edge 


#get the sum 
total = sum(edge.calc_length() for edge in bm.edges if 
return total 


the mistake is in the result.
in the first run of script, i just get the length of a single edge that i selected before (by index)…and then i run again the script, and finally i get the sum of the lengths which is that i hope as a result. Why did this happen?
assume, i have to get the result as ‘total’ 28. a single edge that selected by index is 1.032. i got the result like this :
first run : 28
2nd run : 1.032
3rd run and so on : 28…
thanks before for helping me. :’)

I would try going back into Object mode before counting the edges (After you have used ‘bpy.ops.mesh.loop_multi_select()’ to select the edge loop).

I’m not 100% on what bm.select_flush(…) does and I have never done anything with bmesh, but 2.62 requires leaving edit mode for the Python API to see selections made in Edit mode correctly.