Skip to content

Instantly share code, notes, and snippets.

@zeffii
Last active March 18, 2024 23:50
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zeffii/3839812 to your computer and use it in GitHub Desktop.
Save zeffii/3839812 to your computer and use it in GitHub Desktop.
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
Copy link

mazeto commented Mar 3, 2015

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

@Spirit412
Copy link

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

@zeffii
Copy link
Author

zeffii commented May 9, 2016

@mazeto @Spirit412 What errors are you getting?

@zeffii
Copy link
Author

zeffii commented May 9, 2016

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

@thuydtd
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
Copy link

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
Copy link

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

@eddy593
Copy link

eddy593 commented Mar 18, 2024

Information of entity for blender 4.x
https://eddy593.gumroad.com/l/ajafv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment