Reply To: Determining the length of an edge ring

Forum Archive Determining the length of an edge ring Reply To: Determining the length of an edge ring

#92619
Dwayne Savage
Participant

    If you want to go the python route:

    import bpy
    # Get the active object
    obj = bpy.context.active_object # Check if the object is a mesh if obj.type == 'MESH':     # Enter edit mode     bpy.ops.object.mode_set(mode='EDIT')     total_length = 0     # Get the selected edges     edges = [e for e in obj.data.edges if e.select]     # Calculate the length of each selected edge     for edge in edges:         v1 = obj.data.vertices[edge.vertices[0]].co         v2 = obj.data.vertices[edge.vertices[1]].co         length = (v2 - v1).length         #add the edge lengths together         total_length = total_length+length     #Print the total length to the console     print(f"Total length: {total_length}")

    This will output the total length of selected edges. I don’t know why but for some reason you have to go to object mode and back into edit mode for blender to detect the change to the selected edges. It’s probably because of my method of determining selected edges. It’s the only thing I could come up with. So, I added a mode set to edit. This way you can just select your edges tab to object mode and run the script. Now that I’m typing this I could have just switched to object mode instead. I think. 

    bpy.ops.object.mode_set(mode='OBJECT')

    I haven’t tested that. The script does work in object mode. For windows user to access the console click windows->Toggle System Console. For Linux user you can add “-con” without the quotes after running ./blender in the terminal or if you have a menu item or desktop icon you can check run in terminal for the launchers properties. Sorry, Mac people I don’t know on Mac, but I do know you can use the -con in terminal mode. 

    ***Edit*** It works. So here is the change so you don’t have to tab to object mode.

    import bpy
    # Get the active object obj = bpy.context.active_object # Check if the object is a mesh if obj.type == 'MESH':     # Enter edit mode     bpy.ops.object.mode_set(mode='OBJECT')     bpy.ops.object.mode_set(mode='EDIT')     total_length = 0     # Get the selected edges     edges = [e for e in obj.data.edges if e.select]     # Calculate the length of each selected edge     for edge in edges:         v1 = obj.data.vertices[edge.vertices[0]].co         v2 = obj.data.vertices[edge.vertices[1]].co         length = (v2 - v1).length         #add the edge lengths together         total_length = total_length+length     #Print the total length to the console     print(f"Total length: {total_length}")