The distance of two selected vertices can now be measured. If several
authorClemens Barth <barth@root-1.de>
Sat, 1 Dec 2012 20:59:03 +0000 (20:59 +0000)
committerClemens Barth <barth@root-1.de>
Sat, 1 Dec 2012 20:59:03 +0000 (20:59 +0000)
vertices are selected, the first two are taken.

Blendphys

io_atomblend_utilities/io_atomblend_utilities.py

index 15c14399b0d1beef70ffc2c9075d08e5d129b6b5..ae8d531e161dbf103d29309f76d975c7d50ac176 100644 (file)
@@ -178,13 +178,32 @@ class ElementProp(object):
 # which are active.
 def distance():
 
-    if len(bpy.context.selected_bases) > 1:
-        object_1 = bpy.context.selected_objects[0]
-        object_2 = bpy.context.selected_objects[1]
+    # In the 'Edit mode'
+    if bpy.context.mode == 'EDIT_MESH':
+
+        obj = bpy.context.edit_object
+        bm = bmesh.from_edit_mesh(obj.data)
+        locations = []
+
+        for v in bm.verts:
+            if v.select:
+                locations.append(obj.matrix_world * v.co)
+                
+        if len(locations) > 1:
+            location1 = locations[0]
+            location2 = locations[1]        
+        else:
+            return "N.A"
+    # In the object mode
     else:
-        return "N.A."
 
-    dv = object_2.location - object_1.location
+        if len(bpy.context.selected_bases) > 1:
+            location1 = bpy.context.selected_objects[0].location
+            location2 = bpy.context.selected_objects[1].location
+        else:
+            return "N.A."
+
+    dv = location2 - location1
     dist = str(dv.length)
     pos = str.find(dist, ".")
     dist = dist[:pos+4]