[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [20342] trunk/blender/release/scripts/ wizard_bolt_factory.py: Update to the bolt/nut script, I also replaced some loops with list-comprehension and use mesh.transform( matrix) rather then transforming every vert in a loop.

Campbell Barton ideasman42 at gmail.com
Fri May 22 14:31:27 CEST 2009


Revision: 20342
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=20342
Author:   campbellbarton
Date:     2009-05-22 14:31:27 +0200 (Fri, 22 May 2009)

Log Message:
-----------
Update to the bolt/nut script, I also replaced some loops with list-comprehension and use mesh.transform(matrix) rather then transforming every vert in a loop.
V2.00 22/05/09 by Aaron Keith

- Better error checking.
- Lock Nut and Hex Nut meshes added.
- Pre-sets for common metric bolts and nuts.
- Improved GUI.
- Meshes scaled to a smaller size
- Fixed bug when using crest and root percent other than 10%
- Can now create meshes in Edit Mode.  This will add to the 
  current mesh and align with the current view.

Modified Paths:
--------------
    trunk/blender/release/scripts/wizard_bolt_factory.py

Modified: trunk/blender/release/scripts/wizard_bolt_factory.py
===================================================================
--- trunk/blender/release/scripts/wizard_bolt_factory.py	2009-05-22 12:07:03 UTC (rev 20341)
+++ trunk/blender/release/scripts/wizard_bolt_factory.py	2009-05-22 12:31:27 UTC (rev 20342)
@@ -1,42 +1,53 @@
 #!BPY
-
+# -*- coding: latin-1 -*-
 """
 Name: 'Bolt Factory'
-Blender: 249
+Blender: 248
 Group: 'Wizards'
-Tooltip: 'Create models of various types to screw fasteners.'
+Tooltip: 'Create models of various types of screw fasteners.'
 """
 
 __author__ = " Aaron Keith (Spudmn) "
-__version__ = "1.50 "
-__url__ = ["blender", "http://wiki.blender.org/index.php/Extensions:Py/Scripts/Manual/Misc/Bolt_Factory"]
-__email__= [""]
+__version__ = "2.00 2009/05/22"
+__url__ = ["Author's site,http://sourceforge.net/projects/boltfactory/", "Blender,http://wiki.blender.org/index.php/Extensions:Py/Scripts/Manual/Misc/Bolt_Factory"]
 __bpydoc__ = """\
 Bolt_Factory.py 
 
 Bolt Factory is a Python script for Blender 3D.
 
-The script allows the user to create models of various types to screw fasteners.
+The script allows the user to create models of various types of screw fasteners.
 
-This version is very much a work in progress.
-
-This is my first attempt to program in Python.  This version is unpolished and
-doesn't do much error checking.  Therefore if the user sets strange
-variable the model created will be as equally strange.
-
 For best results set the material to smooth and apply a Edge Split modifier
 with default settings.
 
-To Do:
-Better error checking.
-Nuts to go with the bolts.
-Pre-sets for common bolts.
-Improved GUI.
-More Head and Bit types. 
-Better documentation.
-Fix error with mesh when using crest and root percent other than 10.
 
+History:
 
+V2.00 22/05/09 by Aaron Keith
+
+- Better error checking.
+- Lock Nut and Hex Nut meshes added.
+- Pre-sets for common metric bolts and nuts.
+- Improved GUI.
+- Meshes scaled to a smaller size
+- Fixed bug when using crest and root percent other than 10%
+- Can now create meshes in Edit Mode.  This will add to the 
+  current mesh and align with the current view.
+
+V1.00 01/04/08 by Aaron Keith
+
+- This version is very much a work in progress.
+- This is my first attempt to program in Python.  This version is
+  unpolished and doesn't do much error checking.  Therefore 
+  if the user sets strange variable the model created will be 
+  as equally strange.
+
+- To Do:
+- Better error checking.
+- More Head and Bit types. 
+- Better documentation.
+
+
 """
 
 # -------------------------------------------------------------------------- 
@@ -44,7 +55,7 @@
 # -------------------------------------------------------------------------- 
 # ***** BEGIN GPL LICENSE BLOCK ***** 
 # 
-# Copyright (C) 2008: Aaron Keith
+# Copyright (C) 2009: Aaron Keith
 # 
 # This program is free software; you can redistribute it and/or 
 # modify it under the terms of the GNU General Public License 
@@ -74,78 +85,75 @@
 from Blender.Mathutils import *
 
 
+#Global_Scale = 0.001    #1 blender unit = X mm
+Global_Scale = 0.1    #1 blender unit = X mm
+#Global_Scale = 1.0    #1 blender unit = X mm
 Global_NutRad = 0.0
 MAX_INPUT_NUMBER = 50
 
 No_Event,On_Preset_Click,On_Apply_Click,On_Create_Click,On_Hex_Click, On_Cap_Click,On_Dome_Click,On_Pan_Click,On_Bit_None_Click,On_Bit_Allen_Click,On_Bit_Philips_Click,On_Exit_Click,On_Model_Bolt_Click,On_Model_Nut_Click,On_Hex_Nut_Click,On_Lock_Nut_Click,On_Test_Click = range(17)  # this is like a ENUM
 
 
-Head_Type={'HEX' : [Draw.Create(1),On_Hex_Click],
-           'CAP' : [Draw.Create(0),On_Cap_Click],
-           'DOME': [Draw.Create(0),On_Dome_Click],
-           'PAN' : [Draw.Create(0),On_Pan_Click]}
+Head_Type={'HEX' : [Draw.Create(1),On_Hex_Click,""],
+           'CAP' : [Draw.Create(0),On_Cap_Click,""],
+           'DOME': [Draw.Create(0),On_Dome_Click,""],
+           'PAN' : [Draw.Create(0),On_Pan_Click,""]}
 
 
-Bit_Type={'NONE' : [Draw.Create(1),On_Bit_None_Click],
-           'ALLEN' : [Draw.Create(0),On_Bit_Allen_Click],
-           'PHILLIPS': [Draw.Create(0),On_Bit_Philips_Click]}
+Bit_Type={'NONE' : [Draw.Create(1),On_Bit_None_Click,""],
+           'ALLEN' : [Draw.Create(0),On_Bit_Allen_Click,""],
+           'PHILLIPS': [Draw.Create(0),On_Bit_Philips_Click,""]}
 
-Model_Type={'BOLT' : [Draw.Create(1),On_Model_Bolt_Click],
-           'NUT' : [Draw.Create(0),On_Model_Nut_Click]}
+Model_Type={'BOLT' : [Draw.Create(1),On_Model_Bolt_Click,"Bolt Settings"],
+           'NUT' : [Draw.Create(0),On_Model_Nut_Click,"Nut Settings"]}
 
-Nut_Type={'HEX' : [Draw.Create(1),On_Hex_Nut_Click],
-           'LOCK' : [Draw.Create(0),On_Lock_Nut_Click]}
+Nut_Type={'HEX' : [Draw.Create(1),On_Hex_Nut_Click,""],
+           'LOCK' : [Draw.Create(0),On_Lock_Nut_Click,""]}
 
 
+Phillips_Bit_Depth = Draw.Create(3.27)
+Philips_Bit_Dia = Draw.Create(5.20)
 
-Phillips_Bit_Depth = Draw.Create(1.0)
-Philips_Bit_Dia = Draw.Create(1.75)
+Allen_Bit_Depth = Draw.Create(4.0)
+Allen_Bit_Flat_Distance = Draw.Create(6.0)
 
-Allen_Bit_Depth = Draw.Create(1.0)
-Allen_Bit_Flat_Distance = Draw.Create(1.25)
+Hex_Head_Height = Draw.Create(5.3)
+Hex_Head_Flat_Distance = Draw.Create(13.0)
 
-Hex_Head_Height = Draw.Create(1.0)
-Hex_Head_Flat_Distance = Draw.Create(2.25)
+Cap_Head_Dia = Draw.Create(13.5)
+Cap_Head_Height = Draw.Create(8.0)
 
-Cap_Head_Dia = Draw.Create(2.25)
-Cap_Head_Height = Draw.Create(1.5)
-Cap_Head_Inside_Rad = 0.0
+Dome_Head_Dia = Draw.Create(16.0)
 
-Dome_Head_Dia = Draw.Create(3.75)
+Pan_Head_Dia = Draw.Create(16.0)
 
-Pan_Head_Dia = Draw.Create(5.375)
+Shank_Dia = Draw.Create(8.0)
+Shank_Length = Draw.Create(0.0)
 
-Shank_Dia = Draw.Create(1.5)
-Shank_Length = Draw.Create(0.125)
+Thread_Length = Draw.Create(16.0)
+Major_Dia = Draw.Create(8.0)
+Minor_Dia = Draw.Create(6.917)
+Pitch = Draw.Create(1.0)
+Crest_Percent = Draw.Create(10)
+Root_Percent = Draw.Create(10)
 
-Thread_Length = Draw.Create(2.5)
-Major_Dia = Draw.Create(1.5)
-Minor_Dia = Draw.Create(1.25)
-Pitch = Draw.Create(0.125)
-Crest_Percent = Draw.Create(1.25)
-Root_Percent = Draw.Create(1.25)
+Hex_Nut_Height = Draw.Create(8.0)
+Hex_Nut_Flat_Distance = Draw.Create(13.0)
 
-Hex_Nut_Height = Draw.Create(1.0)
-Hex_Nut_Flat_Distance = Draw.Create(2.25)
+Preset_Menu = Draw.Create(5)
 
-Preset_Menu = Draw.Create(0.25)
-Preset_Length = Draw.Create(1.5)
 
-
 ##########################################################################################
 ##########################################################################################
 ##                    Miscellaneous Utilities
 ##########################################################################################
 ##########################################################################################
 
-
+# Returns a list of verts rotated by the given matrix. Used by SpinDup
 def Rot_Mesh(verts,matrix):
-        ret = []
-        for v in verts:
-            vec = Vector(v) * matrix
-            ret.append([vec.x,vec.y,vec.z])
-        return ret
+    return [list(Vector(v) * matrix) for v in verts]
 
+# Returns a list of faces that has there index incremented by offset 
 def Copy_Faces(faces,offset):        
     ret = []
     for f in faces:
@@ -155,13 +163,8 @@
         ret.append(fsub)
     return ret
 
-def Move_Verts_Up_Z(VERTS,DISTANCE):        
-    ret = []
-    for v in VERTS:
-        ret.append([v[0],v[1],v[2]+DISTANCE])
-    return ret
 
-
+# Much like Blenders built in SpinDup.
 def SpinDup(VERTS,FACES,DEGREE,DIVISIONS,AXIS):
     verts=[]
     faces=[]
@@ -171,22 +174,20 @@
   
     step = DEGREE/DIVISIONS # set step so pieces * step = degrees in arc
     
-    for i in range(int(DIVISIONS)):
+    for i in xrange(int(DIVISIONS)):
         rotmat = Mathutils.RotationMatrix(step*i, 4, AXIS) # 4x4 rotation matrix, 30d about the x axis.
         Rot = Rot_Mesh(VERTS,rotmat)
         faces.extend(Copy_Faces(FACES,len(verts)))    
-        #print faces
         verts.extend(Rot)
     return verts,faces
 
 
-def Mirror_Verts(VERTS,AXIS):
-    ret = []
-    for v in VERTS:
-        ret.append([0-v[0],v[1],v[2]]) 
-    return ret
+# Returns a list of verts that have been moved up the z axis by DISTANCE
+def Move_Verts_Up_Z(VERTS,DISTANCE):
+    return [[v[0],v[1],v[2]+DISTANCE] for v in VERTS]
 
 
+# Returns a list of verts and faces that has been mirrored in the AXIS 
 def Mirror_Verts_Faces(VERTS,FACES,AXIS,FLIP_POINT =0):
     ret_vert = []
     ret_face = []
@@ -208,42 +209,15 @@
         fsub = []
         for i in range(len(f)):
             fsub.append(f[i]+ offset)
-        fsub.reverse() # filp the order to make norm point out
+        fsub.reverse() # flip the order to make norm point out
         ret_face.append(fsub)
             
     return ret_vert,ret_face
 
-def Lath(tool_V1,tool_V2,verts,faces):
-    
-    #verts = []
-    #faces = []f
-       
-    #verts.append([7.0,6.0,0.0])
-    #verts.append([7.0+10,6.0-10,0.0])
-    #faces.append([3,4])
-        
-    vec1 = Vector(verts[-1])
-    vec2 = Vector(verts[-2])
-    
-    VecOut1,VecR2 = LineIntersect(vec1, vec2,Vector(tool_V1), Vector(tool_V2))
-    
-    vec1 = Vector(verts[-2])
-    vec2 = Vector(verts[-3])
-    
-    VecOut2,VecR2 = LineIntersect(vec1, vec2,Vector(tool_V1), Vector(tool_V2))
-    
-    if VecOut1 != None:
-        if VecOut1 == VecOut2:
-            #print "got it"
-            faces.append([len(verts),len(verts)+1])
-            verts.append([VecOut1.x,VecOut1.y,VecOut1.z])
-            verts.append([VecOut2.x,VecOut2.y,VecOut2.z])
-            #print verts[-1]
-            #print verts[-2]
-    
-    return verts,faces
 
 
+# Returns a list of faces that 
+# make up an array of 4 point polygon. 
 def Build_Face_List_Quads(OFFSET,COLUM,ROW,FLIP = 0):
     Ret =[]
     RowStart = 0;
@@ -261,7 +235,8 @@
     return Ret
 
 
-
+# Returns a list of faces that makes up a fill pattern for a 
+# circle
 def Fill_Ring_Face(OFFSET,NUM,FACE_DOWN = 0):
     Ret =[]
     Face = [1,2,0]
@@ -298,13 +273,24 @@
     return Ret
     
 
+##########################################################################################
+##########################################################################################
+##                    Converter Functions For Bolt Factory 
+##########################################################################################
+##########################################################################################
+
+

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list