Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
preliminary_edge_length addon
bl_info = {
"name": "Edge sum",
"author": "zeffii",
"version": (0, 1, 0),
"blender": (2, 7, 7),
"location": "3d view, N panel",
"description": "Adds edge sum box to Mesh Display.",
"wiki_url": "",
"tracker_url": "",
"category": "3D View"}
# http://blender.stackexchange.com/a/1071/47
# where Adhi suggests the space_view3d_panel_measure import.
import bpy
import bmesh
import space_view3d_panel_measure as pm
def print_details(num_edges, edge_length):
print("number of edges: {0}".format(num_edges))
print("combined length: {0:6f}".format(edge_length))
def get_combined_length(object_reference):
# Get a BMesh representation
bm = bmesh.from_edit_mesh(object_reference.data)
selected_edges = [edge for edge in bm.edges if edge.select]
num_edges = len(selected_edges)
edge_length = 0
for edge in selected_edges:
edge_length += edge.calc_length()
print_details(num_edges, edge_length)
return round(edge_length, 6)
class SumButton(bpy.types.Operator):
bl_idname = "scene.calculate_length"
bl_label = "Sometype of operator"
bpy.types.Scene.sum_addon_length = bpy.props.StringProperty(name = "")
def execute(self, context):
obj_reference = context.active_object
length = get_combined_length(obj_reference)
uinfo = pm.getUnitsInfo()
length = pm.convertDistance(length, uinfo)
context.scene.sum_addon_length = length
return{'FINISHED'}
class CopyLength(bpy.types.Operator):
bl_idname = "scene.copy_length"
bl_label = "copy to clipboard"
def execute(self, context):
context.window_manager.clipboard = context.scene.sum_addon_length
return{'FINISHED'}
def draw_item(self, context):
layout = self.layout
obj = context.object
row = layout.row()
scn = context.scene
# display label and button
if obj:
row.label(text="summed edge length:")
row = layout.row()
split = row.split(percentage=0.50)
col = split.column()
col.prop(scn, 'sum_addon_length')
split = split.split()
col = split.column()
col.operator("scene.calculate_length", text='Sum')
split = split.split()
col = split.column()
col.operator("scene.copy_length", text='Copy')
def register():
bpy.utils.register_module(__name__)
bpy.types.VIEW3D_PT_view3d_meshdisplay.append(draw_item)
def unregister():
bpy.utils.unregister_module(__name__)
bpy.types.VIEW3D_PT_view3d_meshdisplay.remove(draw_item)
if __name__ == "__main__":
register()
@mazeto

This comment has been minimized.

Copy link

mazeto commented Mar 3, 2015

Excellent! Just what I was looking for the whole day! Thanks dude!

@Spirit412

This comment has been minimized.

Copy link

Spirit412 commented Jul 3, 2015

Excellent!
But!!! Dont work in 2.75 and dont calculate summed select area poligons

@zeffii

This comment has been minimized.

Copy link
Owner Author

zeffii commented May 9, 2016

@mazeto @Spirit412 What errors are you getting?

@zeffii

This comment has been minimized.

Copy link
Owner Author

zeffii commented May 9, 2016

@Spirit412 -- it isn't designed to calculate selected polygon area, but it would be easy to add.

@thuydtd

This comment has been minimized.

Copy link

thuydtd commented Jun 29, 2016

I cannot install your addon with Blender 2.77
This is my screenshot.
Thank you.

untitled-1

@Zackrobat

This comment has been minimized.

Copy link

Zackrobat commented Nov 26, 2016

I'm getting a similar error as thuydtd. It looks as though 'Edge Length' depended on 'View3D Measure Panel', which was removed because it was broken.

@zeffii, Is there any chance 'Edge Length' will be updated? I've been using it for making accurate measurements of body parts on character meshes, for clothing design.

@KittenCanaveral

This comment has been minimized.

Copy link

KittenCanaveral commented Apr 23, 2017

This is not working for 2.77c, is there any chance that this will be updated ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.