use new preferences standard and fixes for various blender changes
[blender-addons-contrib.git] / mesh_edge_intersection_tools.py
index 025b2e66fbd8eeecf51523031528f461d133866f..389bfdbae1648a22abda48f56356e2de2f9b1f72 100644 (file)
@@ -21,30 +21,29 @@ END GPL LICENCE BLOCK
 bl_info = {
     "name": "Edge tools : tinyCAD VTX",
     "author": "zeffii",
-    "version": (0,5,1),
-    "blender": (2, 5, 6),
-    "api": 34840,
+    "version": (0, 5, 1),
+    "blender": (2, 56, 0),
     "category": "Mesh",
     "location": "View3D > EditMode > (w) Specials",
-    "warning": "Still under development, bug reports appreciated",
+    "warning": "Still under development",
     "wiki_url": "http://wiki.blender.org/index.php/"\
-        "Extensions:2.5/Py/Scripts/Modeling/Edge_Slice",
+        "Extensions:2.6/Py/Scripts/Modeling/Edge_Slice",
     "tracker_url": "http://projects.blender.org/tracker/"\
         "?func=detail&aid=25227"
    }
 
-'''
+"""
 parts based on Keith (Wahooney) Boshoff, cursor to intersection script and
 Paul Bourke's Shortest Line Between 2 lines, and thanks to PKHG from BA.org
 for attempting to explain things to me that i'm not familiar with.
-TODO: [ ] allow multi selection ( > 2 ) for Slice/Weld intersection mode 
-TODO: [ ] streamline this code ! 
+TODO: [ ] allow multi selection ( > 2 ) for Slice/Weld intersection mode
+TODO: [ ] streamline this code !
 
 1) Edge Extend To Edge ( T )
 2) Edge Slice Intersecting ( X )
 3) Edge Project Converging  ( V )
 
-'''
+"""
 
 import bpy
 import sys
@@ -139,26 +138,26 @@ def ExtendEdge(vX, outer_points, count):
     oe.add(4)
     # Candidate for serious optimization.
     if isPointOnEdge(vX, vA, vB):
-        oe[edge_count].vertices = [vert_count,vert_count+1]
-        oe[edge_count+1].vertices = [vert_count,vert_count+2]
+        oe[edge_count].vertices = [vert_count, vert_count+1]
+        oe[edge_count+1].vertices = [vert_count, vert_count+2]
         # find which of C and D is farthest away from X
         if mDist(vD, vX) > mDist(vC, vX):
-            oe[edge_count+2].vertices = [vert_count,vert_count+3]
-            oe[edge_count+3].vertices = [vert_count+3,vert_count+4]
+            oe[edge_count+2].vertices = [vert_count, vert_count+3]
+            oe[edge_count+3].vertices = [vert_count+3, vert_count+4]
         if mDist(vC, vX) > mDist(vD, vX):
-            oe[edge_count+2].vertices = [vert_count,vert_count+4]
-            oe[edge_count+3].vertices = [vert_count+3,vert_count+4]
+            oe[edge_count+2].vertices = [vert_count, vert_count+4]
+            oe[edge_count+3].vertices = [vert_count+3, vert_count+4]
 
     if isPointOnEdge(vX, vC, vD):
-        oe[edge_count].vertices = [vert_count,vert_count+3]
-        oe[edge_count+1].vertices = [vert_count,vert_count+4]
+        oe[edge_count].vertices = [vert_count, vert_count+3]
+        oe[edge_count+1].vertices = [vert_count, vert_count+4]
         # find which of A and B is farthest away from X 
         if mDist(vB, vX) > mDist(vA, vX):
-            oe[edge_count+2].vertices = [vert_count,vert_count+1]
-            oe[edge_count+3].vertices = [vert_count+1,vert_count+2]
+            oe[edge_count+2].vertices = [vert_count, vert_count+1]
+            oe[edge_count+3].vertices = [vert_count+1, vert_count+2]
         if mDist(vA, vX) > mDist(vB, vX):
-            oe[edge_count+2].vertices = [vert_count,vert_count+2]
-            oe[edge_count+3].vertices = [vert_count+1,vert_count+2]
+            oe[edge_count+2].vertices = [vert_count, vert_count+2]
+            oe[edge_count+3].vertices = [vert_count+1, vert_count+2]
 
 
 #   ProjectGeometry is used to extend two edges to their intersection point.
@@ -172,22 +171,22 @@ def ProjectGeometry(vX, opoint):
         else: return B, A
 
     (o, vert_count, edge_count) =  GetActiveObject()
-    vA, vB = return_distance_checked(vX, Vector((opoint[0][0])),Vector((opoint[0][1])))
-    vC, vD = return_distance_checked(vX, Vector((opoint[1][0])),Vector((opoint[1][1])))
+    vA, vB = return_distance_checked(vX, Vector((opoint[0][0])), Vector((opoint[0][1])))
+    vC, vD = return_distance_checked(vX, Vector((opoint[1][0])), Vector((opoint[1][1])))
     AddVertsToObject(vert_count, o, vX, vA, vB, vC, vD)
 
     oe = o.data.edges
     oe.add(4)
     oe[edge_count].vertices = [vert_count, vert_count+1]
     oe[edge_count+1].vertices = [vert_count, vert_count+3]
-    oe[edge_count+2].vertices = [vert_count+1,vert_count+2]
-    oe[edge_count+3].vertices = [vert_count+3,vert_count+4]
+    oe[edge_count+2].vertices = [vert_count+1, vert_count+2]
+    oe[edge_count+3].vertices = [vert_count+3, vert_count+4]
 
 
 def getMeshMatrix(obj):
     is_editmode = (obj.mode == 'EDIT')
     if is_editmode:
-       bpy.ops.object.mode_set(mode='OBJECT')
+        bpy.ops.object.mode_set(mode='OBJECT')
 
     (edges, meshMatrix) = ([],[])
     mesh = obj.data
@@ -198,7 +197,7 @@ def getMeshMatrix(obj):
 
     edgenum = 0
     for edge_to_test in edges:
-        p1 = verts[edge_to_test.vertices[0]].co 
+        p1 = verts[edge_to_test.vertices[0]].co
         p2 = verts[edge_to_test.vertices[1]].co
         meshMatrix.append([Vector(p1),Vector(p2)])
         edgenum += 1
@@ -217,36 +216,36 @@ def runCleanUp():
     bpy.ops.object.mode_set(mode='EDIT')
     bpy.ops.mesh.select_all(action='TOGGLE')
     bpy.ops.mesh.select_all(action='TOGGLE')
-    bpy.ops.mesh.remove_doubles(limit=VTX_PRECISION)
-    bpy.ops.mesh.select_all(action='TOGGLE')        #unselect all
+    bpy.ops.mesh.remove_doubles(threshold=VTX_PRECISION)
+    bpy.ops.mesh.select_all(action='TOGGLE') #unselect all
 
 
 def initScriptV(context, self):
     obj = bpy.context.active_object
     meshMatrix = getMeshMatrix(obj)
     (vert_count, edge_count) = getVertEdgeCount()
-    
+
     #need 2 edges to be of any use.
     if len(meshMatrix) < 2: 
         print(str(len(meshMatrix)) +" select, make sure (only) 2 are selected")
         return
-        
+
     #dont go any further if the verts are not coplanar
     if checkIsMatrixCoplanar(meshMatrix): print("seems within tolerance, proceed")
     else: 
         print("check your geometry, or decrease tolerance value")
         return
 
-    #if we reach this point, the edges are coplanar
-    ## force edit mode
+    # if we reach this point, the edges are coplanar
+    # force edit mode
     bpy.ops.object.mode_set(mode='EDIT')
     vSel = bpy.context.active_object.data.total_vert_sel
 
     if checkEdges(meshMatrix, obj) == None: print("lines dont intersect")
     else:
-        count = CountPointOnEdges(checkEdges(meshMatrix, obj),meshMatrix)
+        count = CountPointOnEdges(checkEdges(meshMatrix, obj), meshMatrix)
         if count == 0:
-            ProjectGeometry(checkEdges(meshMatrix, obj),meshMatrix)
+            ProjectGeometry(checkEdges(meshMatrix, obj), meshMatrix)
             runCleanUp()
         else:
             print("The intersection seems to lie on 1 or 2 edges already")
@@ -262,10 +261,10 @@ def initScriptT(context, self):
     if len(meshMatrix) != 2:
         print(str(len(meshMatrix)) +" select 2 edges")
     else:
-        count = CountPointOnEdges(checkEdges(meshMatrix, obj),meshMatrix)
+        count = CountPointOnEdges(checkEdges(meshMatrix, obj), meshMatrix)
         if count == 1:
             print("Good, Intersection point lies on one of the two edges!")
-            ExtendEdge(checkEdges(meshMatrix, obj),meshMatrix, count)
+            ExtendEdge(checkEdges(meshMatrix, obj), meshMatrix, count)
             runCleanUp()    #neutral function, for removing potential doubles
         else:
             print("Intersection point not on chosen edges")
@@ -283,18 +282,18 @@ def initScriptX(context, self):
         if checkEdges(meshMatrix, obj) == None:
             print("lines dont intersect")
         else: 
-            count = CountPointOnEdges(checkEdges(meshMatrix, obj),meshMatrix)
+            count = CountPointOnEdges(checkEdges(meshMatrix, obj), meshMatrix)
             if count == 2:
-                makeGeometryWeld(checkEdges(meshMatrix, obj),meshMatrix)
+                makeGeometryWeld(checkEdges(meshMatrix, obj), meshMatrix)
                 runCleanUp()
-            
+
 
 class EdgeIntersections(bpy.types.Operator):
-    '''Makes a weld/slice/extend to intersecting edges/lines'''
+    """Makes a weld/slice/extend to intersecting edges/lines"""
     bl_idname = 'mesh.intersections'
     bl_label = 'Edge tools : tinyCAD VTX'
     # bl_options = {'REGISTER', 'UNDO'}
-    
+
     mode = bpy.props.IntProperty(name = "Mode",
                     description = "switch between intersection modes",
                     default = 2)
@@ -323,11 +322,11 @@ def menu_func(self, context):
 
 def register():
     bpy.utils.register_class(EdgeIntersections)
-    bpy.types.VIEW3D_MT_edit_mesh_specials.append(menu_func) 
+    bpy.types.VIEW3D_MT_edit_mesh_specials.append(menu_func)
 
 def unregister():
     bpy.utils.unregister_class(EdgeIntersections)
-    bpy.types.VIEW3D_MT_edit_mesh_specials.remove(menu_func) 
+    bpy.types.VIEW3D_MT_edit_mesh_specials.remove(menu_func)
 
 if __name__ == "__main__":
-    register()
\ No newline at end of file
+    register()