Macro screw maker1 2

Description
This macro creates a screw with or without thread, according to ISO standards.



Utilisation
Select the characteristics of the screw and click on the create button

If you select a circle on a hole, or alternativel the inner surface of a circular hole and the circle at top of that hole at the same time, the screw will be placed into the hole with the create button.

Script

 * 1) -*- coding: utf-8 -*-


 * 1) Form implementation generated from reading ui file 'screw_selector.ui'
 * 2) Created: Sat Aug  3 23:19:38 2013
 * 3)      by: PyQt4 UI code generator 4.9.3
 * 4) WARNING! All changes made in this file will be lost!
 * 1) WARNING! All changes made in this file will be lost!
 * 1) WARNING! All changes made in this file will be lost!

""" Macro to generate screws with FreeCAD. Version 1.2 from 17th of August 2013 """
 * Copyright (c) 2013 Ulrich Brammer  *
 * This file is a supplement to the FreeCAD CAx development system.     *
 * This program is free software; you can redistribute it and/or modify *
 * it under the terms of the GNU Lesser General Public License (LGPL)   *
 * as published by the Free Software Foundation; either version 2 of    *
 * the License, or (at your option) any later version.                  *
 * for detail see the LICENCE text file.                                *
 * This software is distributed in the hope that it will be useful,     *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of       *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the         *
 * GNU Library General Public License for more details.                 *
 * You should have received a copy of the GNU Library General Public    *
 * License along with this macro; if not, write to the Free Software    *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  *
 * USA                                                                  *
 * You should have received a copy of the GNU Library General Public    *
 * License along with this macro; if not, write to the Free Software    *
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  *
 * USA                                                                  *
 * USA                                                                  *

__author__ = "Ulrich Brammer "

from PyQt4 import QtCore, QtGui

import FreeCAD, Part, math from FreeCAD import Base import DraftVecUtils

DEBUG = True # set to True to show debug messages

standard_diameters = { 'ISO4017': ('M3',  'M36'), 'ISO4014': ('M4',  'M30'), 'ISO4762': ('M1.6', 'M36'), 'ISO2009': ('M1.6', 'M10'), 'ISO1207': ('M3',  'M10'), 'ISO7380': ('M3',  'M12'), 'ISO7089': ('M1.6', 'M36')}
 * 1) Diameters included in this library/macro
 * 2) The ISO-standards may include more diameters!
 * 3) Dictionary used for user messages

iso4017head={ 'M3': (0.5, 0.2, 4.6, 6.1,   2.0, 0.1,  5.5), 'M4': (0.7, 0.2, 5.9, 7.7,   3.5, 0.2,  7.0), 'M5': (0.8, 0.2, 6.9, 8.9,   3.5, 0.2,  8.0), 'M6': (1.0, 0.2, 8.9, 11.05, 4.0, 0.25, 10.0), 'M8': (1.25, 0.3, 11.7, 14.5, 5.3, 0.25, 13.0), 'M10':(1.50, 0.3, 14.7, 17.9, 6.4, 0.4,  16.0), 'M12':(1.75, 0.3, 16.7, 20.1, 7.5, 0.6,  18.0), 'M14':(2.00, 0.3, 20.5, 24.5, 8.8, 0.6,  22.0), 'M16':(2.00, 0.4, 22.4, 26.9, 10.0, 0.6, 24.0), 'M20':(2.50, 0.4, 28.2, 33.7, 12.5, 0.8, 30.0), 'M24':(3.00, 0.4, 33.7, 40.1, 15.0, 0.8, 36.0), 'M27':(3.00, 0.4, 38.0, 45.2, 17.0, 1.0, 41.0), 'M30':(3.50, 0.4, 42.8, 50.9, 18.7, 1.0, 46.0), #dw not in class A, e not in class A   'M36':(4.00, 0.4, 51.2, 61.0, 22.5, 55.0)} #dw not in class A, e not in class A
 * 1)         P,    c,  dw,    e,     k,   r,   s

iso4017length = { '12':(11.65, 12.35),  '14':(13.65, 14.35),   '16':(15.65, 16.35),   '20':(19.58, 20.42),   '25':(24.58, 25.42),   '30':(29.58, 30.42),   '35':(34.5,  35.5),   '40':(39.5,  40.5),   '45':(44.5,  45.5),   '50':(49.5,  50.5),   '55':(54.4, 55.6),   '60':(59.4, 60.6),   '65':(64.4, 65.6),   '70':(69.4, 70.6),   '80':(79.4, 80.6),   '100':(99.3, 100.7),   '110':(109.3, 110.7),   '120':(119.3, 120.7),   '130':(129.2, 130.8),   '140':(139.2, 130.8),   '150':(149.2, 150.8),   '160':(159.2, 160.8),   '180':(179.2, 180.8),   '200':(199.1, 200.9)         }

iso4017range = { 'M3': ('5', '30'), 'M4': ('6', '40'), 'M5': ('8', '50'), 'M6': ('12', '60'), 'M8': ('16', '80'), 'M10':('20', '100'), 'M12':('25','120'), 'M14':('25','100'), # www.agriti.com 'M16':('30','150'), 'M20':('40','160'), 'M24':('50','180'), 'M27':('50','100'), 'M30':('60','200'), 'M36':('70','200')}
 * 1) range of typical srew lengths
 * 2)    min_length,  max_length

iso4014head={ 'M4': (0.70, 14.0, 0.0,  0.0, 0.2, 5.9,  7.7,   3.5, 0.2, 7.0), 'M5': (0.80, 16.0, 0.0,  0.0, 0.2, 6.9,  8.9,   3.5, 0.2, 8.0), 'M6': (1.00, 18.0, 24.0, 37.0, 0.2, 8.9, 11.05, 4.0, 0.25, 10.0), 'M8': (1.25, 22.0, 28.0, 41.0, 0.3, 11.7, 14.5, 5.3, 0.4, 13.0), 'M10':(1.50, 26.0, 32.0, 45.0, 0.3, 14.7, 17.9, 6.4, 0.4, 16.0), 'M12':(1.75, 30.0, 36.0, 49.0, 0.3, 16.7, 20.1, 7.5, 0.6, 18.0), 'M14':(2.00, 34.0, 40.0, 0.0, 0.3, 20.5, 24.5,  8.8, 0.6, 22.0), 'M16':(2.00, 38.0, 44.0, 57.0, 0.4, 22.4, 26.9, 10.0, 0.6, 24.0), 'M20':(2.50, 46.0, 52.0, 65.0, 0.4, 28.2, 33.7, 12.5, 0.8, 30.0), 'M24':(3.00, 54.0, 60.0, 73.0, 0.4, 33.7, 40.1, 15.0, 0.8, 36.0), 'M27':(3.00, 60.0, 66.0, 79.0, 0.4, 38.0, 45.2, 17.0, 1.0, 41.0), 'M30':(3.50, 66.0, 72.0, 85.0, 0.4, 42.8, 50.9, 18.7, 1.0, 46.0)} #dw not in class A, e not in class A  #'M36':(  , 0.4, 51.2, 61.0, 22.5, 55.0)} #dw not in class A, e not in class A
 * 1)          P,   b1,   b2,   b3,   c,  dw,    e,     k,   r,   s

iso4014length = { '25':(24.58, 25.42),  '30':(29.58, 30.42),   '35':(34.5,  35.5),   '40':(39.5,  40.5),   '45':(44.5,  45.5),   '50':(49.5,  50.5),   '55':(54.4, 55.6),   '60':(59.4, 60.6),   '65':(64.4, 65.6),   '70':(69.4, 70.6),   '80':(79.4, 80.6),   '100':(99.3, 100.7),   '110':(109.3, 110.7),   '120':(119.3, 120.7),   '130':(129.2, 130.8),   '140':(139.2, 130.8),   '150':(149.2, 150.8),   '160':(159.2, 160.8),   '180':(179.2, 180.8),   '200':(199.1, 200.9),   '220':(219.1, 220.9)         }

iso4014range = { 'M4': ('25', '50'), 'M5': ('25', '50'), 'M6': ('30', '130'), 'M8': ('30', '180'), 'M10':('35', '150'), 'M12':('50','150'), 'M14':('50','160'), 'M16':('55','200'), 'M20':('60','300'), 'M24':('80','220'), 'M27':('90', '220'), 'M30':('90', '220')}
 * 1) range of typical srew lengths
 * 2)    min_length,  max_length

iso1207length = { #'2.5':(2.3, 2.7),   #'3': ( 2.8,  3.2),   '4': ( 3.76, 4.24),   '5': ( 4.76, 5.24),   '6': ( 5.76, 6.24),   '8': ( 7.71, 8.29),   '10':( 9.71, 10.29),   '12':(11.65, 12.35),   '14':(13.65, 14.35),   '16':(15.65, 16.35),   '20':(19.58, 20.42),   '25':(24.58, 25.42),   '30':(29.58, 30.42),   '35':(34.5,  35.5),   '40':(39.5,  40.5),   '45':(44.5,  45.5),   '50':(49.5,  50.5),   '55':(54.05, 55.95),   '60':(59.05, 60.95),   '65':(64.05, 65.95),   '70':(69.05, 70.95),   '75':(74.05, 75.95),   '80':(79.05, 80.95)      }
 * 1) nom length: l_min, l_max

iso1207def={ #'M1.6':(0.35, 0.7, 25, 3.6, 2.8,       1.0,  0.46, 0.4, 0.4, 0.9), #'M2': (0.40, 0.8, 25, 4.4, 3.6,        1.2,  0.56, 0.5, 0.5, 1.0), #'M2.5':(0.45, 0.9, 25, 5.5, 4.5,       1.5,  0.66, 0.6, 0.6, 1.1), 'M3': (0.50, 1.0, 25.0,  5.5,  5.4,  3.6, 2.0, 0.86, 0.1, 0.85, 1.25), #'M3.5':(0.60, 1.2, 38, 8.2, 7.1,       2.35,1.06, 0.9, 1.0, 1.5), 'M4': (0.70, 1.4, 38.0,  7.0,  6.9,  4.7, 2.6, 1.26, 0.2, 1.1, 1.75), 'M5': (0.80, 1.6, 38.0,  8.5,  8.4,  5.7, 3.3, 1.26, 0.2, 1.3, 2.0), 'M6': (1.00, 2.0, 38.0, 10.0,  9.9,  6.8, 3.9, 1.66, 0.25,1.6, 2.5), 'M8': (1.25, 2.5, 38.0, 13.0, 12.85, 9.2, 5.0, 2.06, 0.4, 2.0, 3.2), 'M10': (1.50, 3.0, 38.0, 16.0, 15.85, 11.2,6.0, 2.56, 0.4, 2.4, 3.8)}
 * 1) ISO 1207 definitions Class A
 * 2)          P,     a,   b,   dk,  dk_mean, da,  k,  n_min, r, t_min, x

iso1207range = { #'M1.6':('2.5', '16'), #'M2': ('3', '20'), #'M2.5':('4', '25'), 'M3': ('4', '30'), #'M3.5':('6', '35'), 'M4': ('5', '40'), 'M5': ('6', '50'), 'M6': ('8', '60'), 'M8': ('10', '80'), 'M10':('12', '80')}
 * 1) range of typical srew lengths
 * 2)    min_length,  max_length

iso7380length = { #'2.5':(2.3, 2.7),   #'3': ( 2.8,  3.2),   '4': ( 3.76, 4.24),   '5': ( 4.76, 5.24),   '6': ( 5.76, 6.24),   '8': ( 7.71, 8.29),   '10':( 9.71, 10.29),   '12':(11.65, 12.35),   '14':(13.65, 14.35),   '16':(15.65, 16.35),   '20':(19.58, 20.42),   '25':(24.58, 25.42),   '30':(29.58, 30.42),   '35':(34.5,  35.5),   '40':(39.5,  40.5),   '45':(44.5,  45.5),   '50':(49.5,  50.5),   '55':(54.05, 55.95),   '60':(59.05, 60.95)      }
 * 1) Button Head Screw
 * 2) nom length: l_min, l_max

iso7380def={ 'M3': (0.50, 1.0,  3.6,  5.7,  5.5, 2.03, 1.04, 0.1, 1.65, 2.3,  0.2), 'M4': (0.70, 1.4,  4.7,  7.6,  7.4, 2.54, 1.30, 0.2, 2.20, 2.87, 0.3), 'M5': (0.80, 1.6,  5.7,  9.5,  9.3, 3.05, 1.56, 0.2, 2.75, 3.44, 0.38), 'M6': (1.00, 2.0,  6.8, 10.5, 10.3, 4.05, 2.08, 0.25,3.3,  4.58, 0.74), 'M8': (1.25, 2.5,  9.2, 14.0, 13.8, 5.05, 2.60, 0.4, 4.4,  5.72, 1.05), 'M10': (1.50, 3.0, 11.2, 17.5, 17.3, 6.05, 3.12, 0.4, 5.5, 6.86, 1.45), 'M12': (1.75, 3.5, 13.7, 21.0, 20.7, 8.06, 4.16, 0.6, 6.6, 9.15, 1.63), 'M16': (1.75, 3.5, 18.2, 28.0, 27.8, 10.06,5.20, 0.6, 8.8, 9.15, 2.25) }
 * 1) ISO 7380 definitions Class A
 * 2) http://www.agrati.com/it/unificati/it/gamma/unificati/home02.htm
 * 3)          P,     a,   da,   dk,  dk_mean,s_mean,t_min, r, k,   e,    w,

iso7380range = { 'M3': ('5', '25'), 'M4': ('5', '40'), 'M5': ('6', '40'), 'M6': ('8', '60'), 'M8': ('10', '60'), 'M10':('12', '60'), 'M12':('16', '60'), 'M16':('20', '60')}
 * 1) range of typical srew lengths
 * 2)    min_length,  max_length

L_iso2009length =['2.5','3','4','5','6','8','10','12','14','16','20', \ '25','30','35','40','45','50','55','60','65','70','75','80'] iso2009length = { '2.5':(2.3, 2.7),   '3': ( 2.8,  3.2),   '4': ( 3.76, 4.24),   '5': ( 4.76, 5.24),   '6': ( 5.76, 6.24),   '8': ( 7.71, 8.29),   '10':( 9.71, 10.29),   '12':(11.65, 12.35),   '14':(13.65, 14.35),   '16':(15.65, 16.35),   '20':(19.58, 20.42),   '25':(24.58, 25.42),   '30':(29.58, 30.42),   '35':(34.5,  35.5),   '40':(39.5,  40.5),   '45':(44.5,  45.5),   '50':(49.5,  50.5),   '55':(54.05, 55.95),   '60':(59.05, 60.95),   '65':(64.05, 65.95),   '70':(69.05, 70.95),   '75':(74.05, 75.95),   '80':(79.05, 80.95)      }
 * 1) nom length: l_min, l_max

iso2009def={ 'M1.6':(0.35, 0.7, 25, 3.6, 2.8, 1.0,  0.46, 0.4, 0.4, 0.9), 'M2': (0.40, 0.8, 25, 4.4, 3.6,  1.2,  0.56, 0.5, 0.5, 1.0), 'M2.5':(0.45, 0.9, 25, 5.5, 4.5, 1.5,  0.66, 0.6, 0.6, 1.1), 'M3': (0.50, 1.0, 25, 6.3, 5.3,  1.65, 0.86, 0.8, 0.7, 1.25), 'M3.5':(0.60, 1.2, 38, 8.2, 7.1, 2.35, 1.06, 0.9, 1.0, 1.5), 'M4': (0.70, 1.4, 38, 9.4, 8.2,  2.7,  1.26, 1.0, 1.1, 1.75), 'M5': (0.80, 1.6, 38,10.4, 9.2,  2.7,  1.26, 1.3, 1.2, 2.0), 'M6': (1.00, 2.0, 38,12.6, 11.2, 3.3,  1.66, 1.5, 1.4, 2.5), 'M8': (1.25, 2.5, 38,17.3, 15.6, 4.65, 2.06, 2.0, 2.0, 3.2), 'M10': (1.50, 3.0, 38,20.0, 18.1, 5.0, 2.56, 2.5, 2.3, 3.8)} iso2009range = { 'M1.6':('2.5', '16'), 'M2': ('3', '20'), 'M2.5':('4', '25'), 'M3': ('5', '30'), 'M3.5':('6', '35'), 'M4': ('6', '40'), 'M5': ('8', '50'), 'M6': ('8', '60'), 'M8': ('10', '80'), 'M10':('12', '80')}
 * 1) ISO 2009 definitions Class A
 * 2)          P, a, b, dk_theo, dk_mean, k, n_min, r, t_mean, x
 * 1) range of typical srew lengths
 * 2)    min_length,  max_length

iso4762def={ 'M1.6':(0.35, 15.0, 3.0, 2.0,  1.46,  1.73, 0.34,  1.6, 0.1,  1.56,  0.7, 0.16, 2.72, 0.55), 'M2': (0.40, 16.0, 3.8,  2.6,  1.86,  1.73, 0.51,  2.0, 0.1,  1.56,  1.0, 0.2,  3.48, 0.55), 'M2.5':(0.45, 17.0, 4.5, 3.1,  2.36,  2.30, 0.51,  2.5, 0.1,  2.06,  1.1, 0.25, 4.18, 0.85), 'M3': (0.50, 18.0,  5.5,  3.6,  2.86,  2.87, 0.51,  3.0, 0.1,  2.56,  1.3, 0.3,  5.07, 1.15), 'M4': (0.70, 20.0,  7.0,  4.7,  3.82,  3.44, 0.60,  4.0, 0.2,  3.06,  2.0, 0.4,  6.53, 1.40), 'M5': (0.80, 22.0,  8.5,  5.7,  4.82,  4.58, 0.60,  5.0, 0.2,  4.06,  2.5, 0.5,  8.03, 1.9), 'M6': (1.00, 24.0, 10.0,  6.8,  5.82,  5.72, 0.68,  6.0, 0.25, 5.06,  3.0, 0.6,  9.38, 2.3), 'M8': (1.25, 28.0, 13.0,  9.2,  7.78,  6.86, 1.02,  8.0, 0.4,  6.06,  4.0, 0.8, 12.33, 3.3), 'M10': (1.50, 32.0, 16.0, 11.2, 9.78,  9.15, 1.02, 10.0, 0.4,  8.07,  5.0, 1.0, 15.33, 4.0), 'M12': (1.75, 36.0, 18.0, 13.7, 11.73, 11.43, 1.45, 12.0, 0.6, 10.07, 6.0, 1.2, 17.23, 4.8), 'M16': (2.00, 44.0, 24.0, 17.7, 15.73, 16.00, 1.45, 16.0, 0.6, 14.08, 8.0, 1.6, 23.17, 6.8), 'M20': (2.50, 52.0, 30.0, 22.4, 19.67, 19.44, 2.04, 20.0, 0.8, 17.10, 10.0, 2.0, 28.87, 8.6), 'M24': (3.00, 60.0, 36.0, 26.4, 23.67, 21.73, 2.04, 24.0, 0.8, 19.15, 12.0, 2.0, 34.81, 10.4), 'M30': (3.50, 72.0, 45.0, 33.4, 29.67, 25.15, 2.89, 30.0, 1.0, 22.15, 15.5, 2.4, 43,61, 13.1), 'M36': (4.00, 84.0, 54.0, 39.4, 35.61, 30.85, 2.89, 36.0, 1.0, 27.15, 19.0, 3.0, 52.54, 15.3)}
 * 1) ISO 4762 definitions
 * 2)           P,   b,  dk_max, da,  ds_min,   e,    lf,   k,   r,   s_mean, t,    v,   dw,   w

iso4762length = { '2.5':(2.3, 2.7),   '3': ( 2.8,  3.2),   '4': ( 3.76, 4.24),   '5': ( 4.76, 5.24),   '6': ( 5.76, 6.24),   '8': ( 7.71, 8.29),   '10':( 9.71, 10.29),   '12':(11.65, 12.35),   '14':(13.65, 14.35),   '16':(15.65, 16.35),   '20':(19.58, 20.42),   '25':(24.58, 25.42),   '30':(29.58, 30.42),   '35':(34.5,  35.5),   '40':(39.5,  40.5),   '45':(44.5,  45.5),   '50':(49.5,  50.5),   '55':(54.4, 55.6),   '60':(59.4, 60.6),   '65':(64.4, 65.6),   '70':(69.4, 70.6),   '75':(74.4, 75.6),   '80':(79.4, 80.6),   '100':(99.3, 100.7),   '110':(109.3, 110.7),   '120':(119.3, 120.7),   '130':(129.2, 130.8),   '140':(139.2, 130.8),   '150':(149.2, 150.8),   '160':(159.2, 160.8),   '180':(179.2, 180.8),   '200':(199.1, 200.9)      }
 * 1) nom length: l_min, l_max

iso4762range = { 'M1.6':('2.5', '16'), 'M2': ('3', '20'), 'M2.5':('4', '25'), 'M3': ('5', '30'), 'M3.5':('6', '35'), 'M4': ('6', '40'), 'M5': ('8', '50'), 'M6': ('8', '60'), 'M8': ('10', '80'), 'M10':('16', '100'), 'M12':('20', '120'), 'M16':('25', '120'), 'M20':('16', '100'), 'M24':('40', '200'), 'M30':('45', '200'), 'M36':('55', '200') }
 * 1) range of typical srew lengths
 * 2)    min_length,  max_length

iso7089def={ 'M1.6':( 1.7, 4.0, 0.3, 0.35), 'M2': ( 2.2,  5.0, 0.3, 0.35), 'M2.5':( 2.7, 6.0, 0.5, 0.55), 'M3': ( 3.2,  7.0, 0.5, 0.55), 'M4': ( 4.3,  9.0, 0.8, 0.90), 'M5': ( 5.3, 10.0, 1.0, 1.10), 'M6': ( 6.4, 12.0, 1.6, 1.80), 'M8': ( 8.4, 16.0, 1.6, 1.80), 'M10': (10.5, 20.0, 2.0, 2.20), 'M12': (13.0, 24.0, 2.5, 2.70), 'M16': (17.0, 30.0, 3.0, 3.30), 'M20': (21.0, 37.0, 3.0, 3.30), 'M24': (25.0, 44.0, 4.0, 4.30), 'M30': (31.0, 56.0, 4.0, 4.30), 'M36': (37.0, 66.0, 5.0, 5.60), 'M42': (45.0, 78.0, 8.0, 9.0), 'M48': (52.0, 92.0, 8.0, 9.0), 'M56': (62.0,105.0,10.0, 11.0), 'M64': (70.0,115.0,10.0, 11.0) }
 * 1) ISO 7089 definitions
 * 2)           d1_min, d2_max, h, h_max

try: _fromUtf8 = QtCore.QString.fromUtf8 except AttributeError: _fromUtf8 = lambda s: s

class Ui_ScrewMaker(object): def setupUi(self, ScrewMaker): ScrewMaker.setObjectName(_fromUtf8("ScrewMaker")) ScrewMaker.resize(450, 362) ScrewMaker.setLocale(QtCore.QLocale(QtCore.QLocale.English, QtCore.QLocale.UnitedKingdom)) self.layoutWidget = QtGui.QWidget(ScrewMaker) self.layoutWidget.setGeometry(QtCore.QRect(330, 20, 111, 161)) self.layoutWidget.setObjectName(_fromUtf8("layoutWidget")) self.verticalLayout_2 = QtGui.QVBoxLayout(self.layoutWidget) self.verticalLayout_2.setMargin(0) self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2")) self.ScrewTypeLabel = QtGui.QLabel(self.layoutWidget) self.ScrewTypeLabel.setObjectName(_fromUtf8("ScrewTypeLabel")) self.verticalLayout_2.addWidget(self.ScrewTypeLabel) self.NomDiaLabel = QtGui.QLabel(self.layoutWidget) self.NomDiaLabel.setObjectName(_fromUtf8("NomDiaLabel")) self.verticalLayout_2.addWidget(self.NomDiaLabel) self.NomLenLabel = QtGui.QLabel(self.layoutWidget) self.NomLenLabel.setObjectName(_fromUtf8("NomLenLabel")) self.verticalLayout_2.addWidget(self.NomLenLabel) self.ThreadTypeLabel = QtGui.QLabel(self.layoutWidget) self.ThreadTypeLabel.setObjectName(_fromUtf8("ThreadTypeLabel")) self.verticalLayout_2.addWidget(self.ThreadTypeLabel) self.layoutWidget1 = QtGui.QWidget(ScrewMaker) self.layoutWidget1.setGeometry(QtCore.QRect(10, 20, 315, 166)) self.layoutWidget1.setObjectName(_fromUtf8("layoutWidget1")) self.verticalLayout = QtGui.QVBoxLayout(self.layoutWidget1) self.verticalLayout.setMargin(0) self.verticalLayout.setObjectName(_fromUtf8("verticalLayout")) self.ScrewType = QtGui.QComboBox(self.layoutWidget1) self.ScrewType.setObjectName(_fromUtf8("ScrewType")) self.ScrewType.addItem(_fromUtf8("")) self.ScrewType.addItem(_fromUtf8("")) self.ScrewType.addItem(_fromUtf8("")) self.ScrewType.addItem(_fromUtf8("")) self.ScrewType.addItem(_fromUtf8("")) self.ScrewType.addItem(_fromUtf8("")) self.ScrewType.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.ScrewType) self.NominalDiameter = QtGui.QComboBox(self.layoutWidget1) self.NominalDiameter.setObjectName(_fromUtf8("NominalDiameter")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.NominalDiameter.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.NominalDiameter) self.NominalLength = QtGui.QComboBox(self.layoutWidget1) self.NominalLength.setObjectName(_fromUtf8("NominalLength")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.NominalLength.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.NominalLength) self.ThreadType = QtGui.QComboBox(self.layoutWidget1) self.ThreadType.setObjectName(_fromUtf8("ThreadType")) self.ThreadType.addItem(_fromUtf8("")) self.verticalLayout.addWidget(self.ThreadType) self.layoutWidget2 = QtGui.QWidget(ScrewMaker) self.layoutWidget2.setGeometry(QtCore.QRect(10, 200, 321, 83)) self.layoutWidget2.setObjectName(_fromUtf8("layoutWidget2")) self.verticalLayout_3 = QtGui.QVBoxLayout(self.layoutWidget2) self.verticalLayout_3.setMargin(0) self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3")) self.SimpleScrew = QtGui.QRadioButton(self.layoutWidget2) self.SimpleScrew.setChecked(True) self.SimpleScrew.setObjectName(_fromUtf8("SimpleScrew")) self.verticalLayout_3.addWidget(self.SimpleScrew) self.SymbolThread = QtGui.QRadioButton(self.layoutWidget2) self.SymbolThread.setObjectName(_fromUtf8("SymbolThread")) self.verticalLayout_3.addWidget(self.SymbolThread) self.RealThread = QtGui.QRadioButton(self.layoutWidget2) self.RealThread.setObjectName(_fromUtf8("RealThread")) self.verticalLayout_3.addWidget(self.RealThread) self.MessageLabel = QtGui.QLabel(ScrewMaker) self.MessageLabel.setGeometry(QtCore.QRect(20, 290, 411, 21)) self.MessageLabel.setProperty("Empty_text", _fromUtf8("")) self.MessageLabel.setObjectName(_fromUtf8("MessageLabel")) self.CreateButton = QtGui.QToolButton(ScrewMaker) self.CreateButton.setGeometry(QtCore.QRect(180, 320, 111, 26)) self.CreateButton.setObjectName(_fromUtf8("CreateButton")) self.ScrewAvailable = True

self.retranslateUi(ScrewMaker) self.NominalDiameter.setCurrentIndex(5) self.NominalLength.setCurrentIndex(9) QtCore.QObject.connect(self.ScrewType, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.check_Data) QtCore.QObject.connect(self.CreateButton, QtCore.SIGNAL(_fromUtf8("pressed")), self.createScrew) QtCore.QObject.connect(self.NominalDiameter, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.check_Data) QtCore.QObject.connect(self.NominalLength, QtCore.SIGNAL(_fromUtf8("currentIndexChanged(int)")), self.check_Data) QtCore.QMetaObject.connectSlotsByName(ScrewMaker)

def retranslateUi(self, ScrewMaker): ScrewMaker.setWindowTitle(QtGui.QApplication.translate("ScrewMaker", "Screw-Maker", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewTypeLabel.setText(QtGui.QApplication.translate("ScrewMaker", "Type of Screw", None, QtGui.QApplication.UnicodeUTF8)) self.NomDiaLabel.setText(QtGui.QApplication.translate("ScrewMaker", "Nomimal Diameter", None, QtGui.QApplication.UnicodeUTF8)) self.NomLenLabel.setText(QtGui.QApplication.translate("ScrewMaker", "Nominal length", None, QtGui.QApplication.UnicodeUTF8)) self.ThreadTypeLabel.setText(QtGui.QApplication.translate("ScrewMaker", "Thread type", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(0, QtGui.QApplication.translate("ScrewMaker", "ISO4017: Hexagon head screws", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(1, QtGui.QApplication.translate("ScrewMaker", "ISO4014: Hexagon head bolts", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(2, QtGui.QApplication.translate("ScrewMaker", "ISO4762: Hexagon socket head cap screws", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(3, QtGui.QApplication.translate("ScrewMaker", "ISO2009: Slotted countersunk flat head screws", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(4, QtGui.QApplication.translate("ScrewMaker", "ISO1207: Slotted cheese head screws", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(5, QtGui.QApplication.translate("ScrewMaker", "ISO7380: Hexagon socket button head screws", None, QtGui.QApplication.UnicodeUTF8)) self.ScrewType.setItemText(6, QtGui.QApplication.translate("ScrewMaker", "ISO7089: Washer", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(0, QtGui.QApplication.translate("ScrewMaker", "M1.6", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(1, QtGui.QApplication.translate("ScrewMaker", "M2", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(2, QtGui.QApplication.translate("ScrewMaker", "M2.5", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(3, QtGui.QApplication.translate("ScrewMaker", "M3", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(4, QtGui.QApplication.translate("ScrewMaker", "M4", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(5, QtGui.QApplication.translate("ScrewMaker", "M5", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(6, QtGui.QApplication.translate("ScrewMaker", "M6", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(7, QtGui.QApplication.translate("ScrewMaker", "M8", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(8, QtGui.QApplication.translate("ScrewMaker", "M10", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(9, QtGui.QApplication.translate("ScrewMaker", "M12", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(10, QtGui.QApplication.translate("ScrewMaker", "M14", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(11, QtGui.QApplication.translate("ScrewMaker", "M16", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(12, QtGui.QApplication.translate("ScrewMaker", "M20", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(13, QtGui.QApplication.translate("ScrewMaker", "M24", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(14, QtGui.QApplication.translate("ScrewMaker", "M27", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(15, QtGui.QApplication.translate("ScrewMaker", "M30", None, QtGui.QApplication.UnicodeUTF8)) self.NominalDiameter.setItemText(16, QtGui.QApplication.translate("ScrewMaker", "M36", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(0, QtGui.QApplication.translate("ScrewMaker", "2.5", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(1, QtGui.QApplication.translate("ScrewMaker", "3", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(2, QtGui.QApplication.translate("ScrewMaker", "4", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(3, QtGui.QApplication.translate("ScrewMaker", "5", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(4, QtGui.QApplication.translate("ScrewMaker", "6", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(5, QtGui.QApplication.translate("ScrewMaker", "8", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(6, QtGui.QApplication.translate("ScrewMaker", "10", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(7, QtGui.QApplication.translate("ScrewMaker", "12", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(8, QtGui.QApplication.translate("ScrewMaker", "16", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(9, QtGui.QApplication.translate("ScrewMaker", "20", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(10, QtGui.QApplication.translate("ScrewMaker", "25", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(11, QtGui.QApplication.translate("ScrewMaker", "30", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(12, QtGui.QApplication.translate("ScrewMaker", "35", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(13, QtGui.QApplication.translate("ScrewMaker", "40", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(14, QtGui.QApplication.translate("ScrewMaker", "45", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(15, QtGui.QApplication.translate("ScrewMaker", "50", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(16, QtGui.QApplication.translate("ScrewMaker", "55", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(17, QtGui.QApplication.translate("ScrewMaker", "60", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(18, QtGui.QApplication.translate("ScrewMaker", "65", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(19, QtGui.QApplication.translate("ScrewMaker", "70", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(20, QtGui.QApplication.translate("ScrewMaker", "80", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(21, QtGui.QApplication.translate("ScrewMaker", "90", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(22, QtGui.QApplication.translate("ScrewMaker", "100", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(23, QtGui.QApplication.translate("ScrewMaker", "110", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(24, QtGui.QApplication.translate("ScrewMaker", "120", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(25, QtGui.QApplication.translate("ScrewMaker", "130", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(26, QtGui.QApplication.translate("ScrewMaker", "140", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(27, QtGui.QApplication.translate("ScrewMaker", "150", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(28, QtGui.QApplication.translate("ScrewMaker", "160", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(29, QtGui.QApplication.translate("ScrewMaker", "180", None, QtGui.QApplication.UnicodeUTF8)) self.NominalLength.setItemText(30, QtGui.QApplication.translate("ScrewMaker", "200", None, QtGui.QApplication.UnicodeUTF8)) self.ThreadType.setItemText(0, QtGui.QApplication.translate("ScrewMaker", "regular pitch", None, QtGui.QApplication.UnicodeUTF8)) self.SimpleScrew.setText(QtGui.QApplication.translate("ScrewMaker", "Simple Screw (no thread at all!)", None, QtGui.QApplication.UnicodeUTF8)) self.SymbolThread.setText(QtGui.QApplication.translate("ScrewMaker", "Symbol Thread (not implemented yet)", None, QtGui.QApplication.UnicodeUTF8)) self.RealThread.setText(QtGui.QApplication.translate("ScrewMaker", "Real Thread (takes time, may not work above M16)", None, QtGui.QApplication.UnicodeUTF8)) self.MessageLabel.setText(QtGui.QApplication.translate("ScrewMaker", "Select your screw type", None, QtGui.QApplication.UnicodeUTF8)) self.MessageLabel.setProperty("Errortext", QtGui.QApplication.translate("ScrewMaker", "Combination not implemented", None, QtGui.QApplication.UnicodeUTF8)) self.MessageLabel.setProperty("OK_text", QtGui.QApplication.translate("ScrewMaker", "Screw is made", None, QtGui.QApplication.UnicodeUTF8)) self.CreateButton.setText(QtGui.QApplication.translate("ScrewMaker", "create", None, QtGui.QApplication.UnicodeUTF8))

def check_Data(self): FreeCAD.Console.PrintMessage("Data checking" + self.NominalLength.currentText + "\n") #set screw not ok     M_text = "Select your screw type" ST_text = str(self.ScrewType.currentText) ST_text = ST_text.split(':')[0] ND_text = str(self.NominalDiameter.currentText) Type_text = '' if ST_text == 'ISO4017': table = iso4017head tab_len = iso4017length tab_range = iso4017range Type_text = 'Screw' if ST_text == 'ISO2009': table = iso2009def tab_len = iso2009length tab_range = iso2009range Type_text = 'Screw' if ST_text == 'ISO4762': table = iso4762def tab_len = iso4762length tab_range = iso4762range Type_text = 'Screw' if ST_text == 'ISO4014': table = iso4014head tab_len = iso4014length tab_range = iso4014range Type_text = 'Screw' if ST_text == 'ISO1207': table = iso1207def tab_len = iso1207length tab_range = iso1207range Type_text = 'Screw'

if ST_text == 'ISO7380': table = iso7380def tab_len = iso7380length tab_range = iso7380range Type_text = 'Screw'

if ST_text == 'ISO7089': table = iso7089def Type_text = 'Washer'

if ND_text not in table: ND_min, ND_max = standard_diameters[ST_text] M_text = ST_text+' has diameters from '+ ND_min +' to ' + ND_max + ' and not ' + ND_text +'!' self.ScrewAvailable = False # set scew not ok     else: if Type_text == 'Screw': NL_text = str(self.NominalLength.currentText) NL_min, NL_max = tab_range[ND_text] NL_min_float = float(NL_min) NL_max_float = float(NL_max) NL_text_float = float(NL_text) if (NL_text_floatNL_max_float)or(NL_text not in tab_len): M_text = ST_text+'-'+ ND_text +' has lengths from '+ NL_min +' to ' + NL_max + ' and not ' + NL_text +'!' self.ScrewAvailable = False # set screw not ok           else: M_text = ST_text+'-'+ ND_text +'x'+ NL_text +' is in library available! '              self.ScrewAvailable = True #set screw ok        else: # Washers and Nuts M_text = ST_text+'-'+ ND_text +' is in library available! '           self.ScrewAvailable = True #set washer/nut ok     #print "Data checking: ", self.NominalLength.currentText, "\n" self.MessageLabel.setText(QtGui.QApplication.translate("ScrewMaker", M_text, None, QtGui.QApplication.UnicodeUTF8)) FreeCAD.Console.PrintMessage("Set Check_result into text " + str(self.ScrewAvailable) + M_text + "\n")

def createScrew(self): if self.ScrewAvailable: try: # first we check if valid numbers have been entered FreeCAD.Console.PrintMessage("NominalLength: " + self.NominalLength.currentText + "\n") FreeCAD.Console.PrintMessage("NominalDiameter: " + self.NominalDiameter.currentText + "\n") FreeCAD.Console.PrintMessage("SimpleThread: " + str(self.SimpleScrew.isChecked) + "\n") FreeCAD.Console.PrintMessage("SymbolThread: " + str(self.SymbolThread.isChecked) + "\n") FreeCAD.Console.PrintMessage("RealThread: " + str(self.RealThread.isChecked) + "\n") ND_text = str(self.NominalDiameter.currentText) NL_text = str(self.NominalLength.currentText) ST_text = str(self.ScrewType.currentText) ST_text = ST_text.split(':')[0] dia = float(ND_text.lstrip('M')) l = float(NL_text) if ST_text == 'ISO4017': table = iso4017head if ST_text == 'ISO4014': table = iso4014head if ST_text == 'ISO2009': table = iso2009def if ST_text == 'ISO4762': table = iso4762def if ST_text == 'ISO1207': table = iso1207def if ST_text == 'ISO7380': table = iso7380def if ST_text == 'ISO7089': table = iso7089def if ND_text not in table: FreeCAD.Console.PrintMessage("Combination of type "+ST_text \                   + " and diameter " + ND_text +" not available!" + "\n") #self.MessageLabel.setText(QtGui.QApplication.translate("ScrewMaker", "not implemented", None, QtGui.QApplication.UnicodeUTF8)) except ValueError: print "Error! nom_dia and length values must be valid numbers!" else: doc=App.activeDocument done = False if ST_text == 'ISO4017': FreeCAD.Console.PrintMessage("screw Type ISO4017 selected "+ str(dia) +" "+ str(l) + "\n") screw = self.makeIso4017(ND_text,l) Type_text = 'Screw' done = True if ST_text == 'ISO4014': FreeCAD.Console.PrintMessage("screw Type ISO4014 selected "+ str(dia) +" "+ str(l) + "\n") screw = self.makeIso4014(ND_text,l) Type_text = 'Screw' done = True if ST_text == 'ISO2009': FreeCAD.Console.PrintMessage("screw Type ISO2009 selected "+ str(dia) +" "+ str(l) + "\n") screw = self.makeIso2009(ND_text,l) Type_text = 'Screw' done = True if ST_text == 'ISO4762': FreeCAD.Console.PrintMessage("screw Type ISO4762 selected "+ str(dia) +" "+ str(l) + "\n") screw = self.makeIso4762(ND_text,l) Type_text = 'Screw' done = True if ST_text == 'ISO1207': FreeCAD.Console.PrintMessage("screw Type ISO1207 selected "+ str(dia) +" "+ str(l) + "\n") screw = self.makeIso1207(ND_text,l) Type_text = 'Screw' done = True if ST_text == 'ISO7380': FreeCAD.Console.PrintMessage("screw Type ISO7380 selected "+ str(dia) +" "+ str(l) + "\n") screw = self.makeIso7380(ND_text,l) Type_text = 'Screw' done = True if ST_text == 'ISO7089': FreeCAD.Console.PrintMessage("washer Type ISO7089 selected "+ str(dia) + "\n") screw = self.makeIso7089(ND_text) Type_text = 'Washer' done = True if not done: FreeCAD.Console.PrintMessage("No valid Screw Type!" + "\n") if Type_text == 'Screw': label = ST_text + '-' + ND_text +'x'+ NL_text +'_' else: label = ST_text + '-' + ND_text.lstrip('M') +'_' ScrewObj = doc.addObject("Part::Feature",label) #ScrewObj = doc.addObject("Part::Feature","Screw") ScrewObj.Shape=screw FreeCAD.Console.PrintMessage("Placement: "+ str(ScrewObj.Placement) +"\n") self.moveScrew(ScrewObj) #ScrewObj.Label = label doc.recompute # Part.show(screw) return ScrewObj def moveScrew(self, ScrewObj_m): FreeCAD.Console.PrintMessage("In Move Screw: " + str(ScrewObj_m) + "\n")

mylist = Gui.Selection.getSelectionEx if (mylist.__len__ == 1): # check selection FreeCAD.Console.PrintMessage("Selektionen: " + str(mylist.__len__) + "\n") Pnt1 = None Axis1 = None Axis2 = None for o in Gui.Selection.getSelectionEx: #for s in o.SubElementNames: #FreeCAD.Console.PrintMessage( "name: " + str(s) + "\n") for s in o.SubObjects: #FreeCAD.Console.PrintMessage( "object: "+ str(s) + "\n") if hasattr(s,"Curve"): #FreeCAD.Console.PrintMessage( "The Object is a Curve!\n") if hasattr(s.Curve,"Center"): """                    FreeCAD.Console.PrintMessage( "The object has a Center!\n")                     FreeCAD.Console.PrintMessage( "Curve attribut. "+ str(s.__getattribute__('Curve')) + "\n")                     FreeCAD.Console.PrintMessage( "Center: "+ str(s.Curve.Center) + "\n")                     FreeCAD.Console.PrintMessage( "Axis: "+ str(s.Curve.Axis) + "\n")                     """ Pnt1 = s.Curve.Center Axis1 = s.Curve.Axis if hasattr(s,'Surface'): #print 'the object is a face!' if hasattr(s.Surface,'Axis'): Axis1 = s.Surface.Axis if hasattr(s,'Point'): FreeCAD.Console.PrintMessage( "the object seems to be a vertex! "+ str(s.Point) + "\n") Pnt1 = s.Point if (Axis1 != None): #FreeCAD.Console.PrintMessage( "Got Axis1: " + str(Axis1) + "\n") Axis2 = Base.Vector(0.0,0.0,1.0) Axis2_minus = Base.Vector(0.0,0.0,-1.0) # Calculate angle if Axis1 == Axis2: normvec = Base.Vector(1.0,0.0,0.0) result = 0.0 else: if Axis1 == Axis2_minus: normvec = Base.Vector(1.0,0.0,0.0) result = math.pi              else: normvec = Axis1.cross(Axis2) # Berechne Achse der Drehung = normvec normvec.normalize # Normalisieren fuer Quaternionenrechnung #normvec_rot = normvec result = DraftVecUtils.angle(Axis1, Axis2, normvec) # Winkelberechnung sin_res = math.sin(result/2.0) cos_res = math.cos(result/2.0) normvec.multiply(-sin_res) # Berechnung der Quaternionen-Elemente #FreeCAD.Console.PrintMessage( "Winkel = "+ str(math.degrees(result)) + "\n") #FreeCAD.Console.PrintMessage("Normalvektor: "+ str(normvec) + "\n") pl = FreeCAD.Placement pl.Rotation = (normvec.x,normvec.y,normvec.z,cos_res) #Drehungs-Quaternion #FreeCAD.Console.PrintMessage("pl mit Rot: "+ str(pl) + "\n") #neuPlatz = Part2.Object.Placement.multiply(pl) neuPlatz = ScrewObj_m.Placement #FreeCAD.Console.PrintMessage("die Position    "+ str(neuPlatz) + "\n") neuPlatz.Rotation = pl.Rotation.multiply(ScrewObj_m.Placement.Rotation) neuPlatz.move(Pnt1) #FreeCAD.Console.PrintMessage("die rot. Position: "+ str(neuPlatz) + "\n")

# make Washer def makeIso7089(self,ThreadType ='M6'): dia=float(ThreadType.lstrip('M')) FreeCAD.Console.PrintMessage("die Scheibe mit dia: " + str(dia) + "\n") d1_min, d2_max, h, h_max = iso7089def[ThreadType]

FreeCAD.Console.PrintMessage("die Scheibe mit d1_min: " + str(d1_min) + "\n")

#Washer Points Pnt0 = Base.Vector(d1_min/2.0,0.0,h_max) Pnt2 = Base.Vector(d2_max/2.0,0.0,h_max) Pnt3 = Base.Vector(d2_max/2.0,0.0,0.0) Pnt4 = Base.Vector(d1_min/2.0,0.0,0.0) edge1 = Part.makeLine(Pnt0,Pnt2) edge2 = Part.makeLine(Pnt2,Pnt3) edge3 = Part.makeLine(Pnt3,Pnt4) edge4 = Part.makeLine(Pnt4,Pnt0) FreeCAD.Console.PrintMessage("Edges made Pnt2: " + str(Pnt2) + "\n")

aWire=Part.Wire([edge1,edge2,edge3,edge4]) #Part.show(aWire) aFace =Part.Face(aWire) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) FreeCAD.Console.PrintMessage("Washer revolved: " + str(dia) + "\n")

return head

# make Cheese head slotted screw def makeIso1207(self,ThreadType ='M6',l=25.0): dia=float(ThreadType.lstrip('M')) FreeCAD.Console.PrintMessage("der Kopf mit l: " + str(l) + "\n") P, a, b, dk, dk_mean, da, k, n_min, r, t_min, x = iso1207def[ThreadType]

#FreeCAD.Console.PrintMessage("der Kopf mit iso: " + str(dk) + "\n") #Length for calculation of head fillet r_fil = r     beta = math.radians(5.0)   # angle of cheese head edge alpha = math.radians(90.0 - (90.0+5.0)/2.0) tan_beta = math.tan(beta) # top head diameter without fillet rK_top = dk/2.0 - k * tan_beta fillet_center_x = rK_top - r_fil + r_fil * tan_beta fillet_center_z = k - r_fil fillet_arc_x = fillet_center_x + r_fil * math.sin(alpha) fillet_arc_z = fillet_center_z + r_fil * math.cos(alpha) #FreeCAD.Console.PrintMessage("rK_top: " + str(rK_top) + "\n")

if (b > l - P): bmax = l-P else: bmax = b     turns = round((bmax+P)/P) # number of thread turns a_real = l-turns*P # starting point of thread sqrt2_ = 1.0/math.sqrt(2.0)

#Head Points Pnt0 = Base.Vector(0.0,0.0,k) Pnt2 = Base.Vector(fillet_center_x,0.0,k) Pnt3 = Base.Vector(fillet_arc_x,0.0,fillet_arc_z) Pnt4 = Base.Vector(fillet_center_x + r_fil*math.cos(beta),0.0,fillet_center_z+ r_fil * math.sin(beta)) Pnt5 = Base.Vector(dk/2.0,0.0,0.0) Pnt6 = Base.Vector(dia/2.0+r,0.0,0.0)    #start of fillet between head and shank Pnt7 = Base.Vector(dia/2.0+r-r*sqrt2_,0.0,-r+r*sqrt2_) #arc-point of fillet Pnt8 = Base.Vector(dia/2.0,0.0,-r)       # end of fillet Pnt9 = Base.Vector(dia/2.0,0.0,-a_real)       # Start of thread #FreeCAD.Console.PrintMessage("Points defined fillet_center_x: " + str(fillet_center_x) + "\n") edge1 = Part.makeLine(Pnt0,Pnt2) edge2 = Part.Arc(Pnt2,Pnt3,Pnt4).toShape edge3 = Part.makeLine(Pnt4,Pnt5) edge4 = Part.makeLine(Pnt5,Pnt6) edge5 = Part.Arc(Pnt6,Pnt7,Pnt8).toShape edge6 = Part.makeLine(Pnt8,Pnt9) #FreeCAD.Console.PrintMessage("Edges made fillet_center_z: " + str(fillet_center_z) + "\n") # bolt points PntB1 = Base.Vector(dia/2.0,0.0,-l-P) PntB2 = Base.Vector(0.0,0.0,-l-P) edgeB1 = Part.makeLine(Pnt9,PntB1) edgeB2 = Part.makeLine(PntB1,PntB2) edgeZ0 = Part.makeLine(PntB2,Pnt0) aWire=Part.Wire([edge1,edge2,edge3,edge4,edge5,edge6, \         edgeB1, edgeB2, edgeZ0]) #Part.show(aWire) aFace =Part.Face(aWire) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) #FreeCAD.Console.PrintMessage("der Kopf mit revolve: " + str(dia) + "\n")

#Parameter for slot-recess: dk, n_min, k, t_min slot = Part.makePlane(dk, n_min, \         Base.Vector(dk/2.0,-n_min/2.0,k),Base.Vector(0.0,0.0,-1.0)) slot = slot.extrude(Base.Vector(0.0,0.0,-t_min)) #Part.show(slot) head = head.cut(slot) #FreeCAD.Console.PrintMessage("der Kopf geschnitten: " + str(dia) + "\n") if self.RealThread.isChecked: head = self.cutIsoThread(head, dia, P, turns, l)     #cyl = self.cutChamfer(dia, P, l)      cyl = Part.makeCylinder(dia/2.0,P,Base.Vector(0.0,0.0,-l-P),Base.Vector(0.0,0.0,1.0),360) head = head.cut(cyl) return head

# helper method to create the Hex-head-screw def makeIso4017(self,ThreadType ='M6',l=25.0): dia=float(ThreadType.lstrip('M')) FreeCAD.Console.PrintMessage("der Kopf mit l: " + str(l) + "\n") P, c, dw, e,k,r,s = iso4017head[ThreadType] FreeCAD.Console.PrintMessage("der Kopf mit iso: " + str(c) + "\n") cham = (e-s)*math.sin(math.radians(15)) # needed for chamfer at head top #cham_t = P*math.sqrt(3.0)/2.0*17.0/24.0 turns = round((l-2*P)/P) # number of thread turns a = l-turns*P # starting point of thread sqrt2_ = 1.0/math.sqrt(2.0)

#Head Points Usage of k, s, cham, c, dw, dia, r, a      FreeCAD.Console.PrintMessage("der Kopf mit math a: " + str(a) + "\n") Pnt0 = Base.Vector(0.0,0.0,k) Pnt2 = Base.Vector(s/2.0,0.0,k) Pnt3 = Base.Vector(s/math.sqrt(3.0),0.0,k-cham) Pnt4 = Base.Vector(s/math.sqrt(3.0),0.0,c) Pnt5 = Base.Vector(dw/2.0,0.0,c) Pnt6 = Base.Vector(dw/2.0,0.0,0.0) Pnt7 = Base.Vector(dia/2.0+r,0.0,0.0)    #start of fillet between head and shank Pnt8 = Base.Vector(dia/2.0+r-r*sqrt2_,0.0,-r+r*sqrt2_) #arc-point of fillet Pnt9 = Base.Vector(dia/2.0,0.0,-r)       # end of fillet Pnt10 = Base.Vector(dia/2.0,0.0,-a)       # Start of thread edge1 = Part.makeLine(Pnt0,Pnt2) edge2 = Part.makeLine(Pnt2,Pnt3) edge3 = Part.makeLine(Pnt3,Pnt4) edge4 = Part.makeLine(Pnt4,Pnt5) edge5 = Part.makeLine(Pnt5,Pnt6) edge6 = Part.makeLine(Pnt6,Pnt7) edge7 = Part.Arc(Pnt7,Pnt8,Pnt9).toShape edge8 = Part.makeLine(Pnt9,Pnt10) # bolt points PntB0 = Base.Vector(0.0,0.0,-a) PntB1 = Base.Vector(dia/2.0,0.0,-l-P) PntB2 = Base.Vector(0.0,0.0,-l-P) edgeB1 = Part.makeLine(Pnt10,PntB1) edgeB2 = Part.makeLine(PntB1,PntB2) edgeZ0 = Part.makeLine(PntB2,Pnt0) aWire=Part.Wire([edge1,edge2,edge3,edge4,edge5,edge6,edge7,edge8, \         edgeB1, edgeB2, edgeZ0]) aFace =Part.Face(aWire) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) #FreeCAD.Console.PrintMessage("der Kopf mit revolve: " + str(dia) + "\n")

# create cutting tool for hexagon head # Parameters s, k, outer circle diameter = e/2.0+10.0 extrude = self.makeHextool(s, k, e/2.0+10.0)

# Part.show(extrude) head = head.cut(extrude) FreeCAD.Console.PrintMessage("der Kopf geschnitten: " + str(dia) + "\n") if self.RealThread.isChecked: head = self.cutIsoThread(head, dia, P, turns, l)     cyl = self.cutChamfer(dia, P, l)      #cyl = Part.makeCylinder(dia/2.0,P,Base.Vector(0.0,0.0,-l-P),Base.Vector(0.0,0.0,1.0),360) head = head.cut(cyl) return head

# helper method to create the Hex-head-screw def makeIso4014(self,ThreadType ='M6',l=25.0): dia=float(ThreadType.lstrip('M')) FreeCAD.Console.PrintMessage("der Kopf mit l: " + str(l) + "\n") P, b1, b2, b3, c, dw, e, k, r, s = iso4014head[ThreadType] if l<= 125.0: b = b1     else: if l<= 200.0: b = b2        else: b = b3     FreeCAD.Console.PrintMessage("der Kopf mit iso4014: " + str(c) + "\n") cham = (e-s)*math.sin(math.radians(15)) # needed for chamfer at head top turns = round((b+P)/P) # number of thread turns a = l-turns*P # starting point of thread sqrt2_ = 1.0/math.sqrt(2.0)

#Head Points FreeCAD.Console.PrintMessage("der Kopf mit math a: " + str(a) + "\n") Pnt0 = Base.Vector(0.0,0.0,k) Pnt2 = Base.Vector(s/2.0,0.0,k) #Pnt3 = Base.Vector(e/2.0,0.0,k-cham)  #s/math.sqrt(3.0) #Pnt4 = Base.Vector(e/2.0,0.0,c) Pnt3 = Base.Vector(s/math.sqrt(3.0),0.0,k-cham)  #s/math.sqrt(3.0) Pnt4 = Base.Vector(s/math.sqrt(3.0),0.0,c) Pnt5 = Base.Vector(dw/2.0,0.0,c) Pnt6 = Base.Vector(dw/2.0,0.0,0.0) Pnt7 = Base.Vector(dia/2.0+r,0.0,0.0)    #start of fillet between head and shank Pnt8 = Base.Vector(dia/2.0+r-r*sqrt2_,0.0,-r+r*sqrt2_) #arc-point of fillet Pnt9 = Base.Vector(dia/2.0,0.0,-r)       # end of fillet Pnt10 = Base.Vector(dia/2.0,0.0,-a)       # Start of thread edge1 = Part.makeLine(Pnt0,Pnt2) edge2 = Part.makeLine(Pnt2,Pnt3) edge3 = Part.makeLine(Pnt3,Pnt4) edge4 = Part.makeLine(Pnt4,Pnt5) edge5 = Part.makeLine(Pnt5,Pnt6) edge6 = Part.makeLine(Pnt6,Pnt7) edge7 = Part.Arc(Pnt7,Pnt8,Pnt9).toShape edge8 = Part.makeLine(Pnt9,Pnt10) # bolt points PntB0 = Base.Vector(0.0,0.0,-a) PntB1 = Base.Vector(dia/2.0,0.0,-l-P) PntB2 = Base.Vector(0.0,0.0,-l-P) edgeB1 = Part.makeLine(Pnt10,PntB1) edgeB2 = Part.makeLine(PntB1,PntB2) edgeZ0 = Part.makeLine(PntB2,Pnt0) aWire=Part.Wire([edge1,edge2,edge3,edge4,edge5,edge6,edge7,edge8, \         edgeB1, edgeB2, edgeZ0]) aFace =Part.Face(aWire) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) #FreeCAD.Console.PrintMessage("der Kopf mit revolve: " + str(dia) + "\n")

# create cutting tool for hexagon head # Parameters s, k, outer circle diameter = e/2.0+10.0 extrude = self.makeHextool(s, k, e/2.0+10.0)

# Part.show(extrude) head = head.cut(extrude) #FreeCAD.Console.PrintMessage("der Kopf geschnitten: " + str(dia) + "\n") if self.RealThread.isChecked: head = self.cutIsoThread(head, dia, P, turns, l)     cyl = self.cutChamfer(dia, P, l)      #cyl = Part.makeCylinder(dia/2.0,P,Base.Vector(0.0,0.0,-l-P),Base.Vector(0.0,0.0,1.0),360) head = head.cut(cyl) return head

# make ISO 2009 def makeIso2009(self,ThreadType ='M6',l=25.0): dia=float(ThreadType.lstrip('M')) #FreeCAD.Console.PrintMessage("der 2009Kopf mit l: " + str(l) + "\n") P, a, b, dk_theo, dk_mean, k, n_min, r, t_mean, x = iso2009def[ThreadType] #FreeCAD.Console.PrintMessage("der Kopf mit iso r: " + str(r) + "\n") cham = (dk_theo - dk_mean)/2.0 rad225 = math.radians(22.5) rad45 = math.radians(45.0) rtan = r*math.tan(rad225) if (b > l - k -a): bmax = l-k-a else: bmax = b     turns = round((bmax+P/2.0)/P) # number of thread turns a_real = l-turns*P # starting point of thread #Head Points #FreeCAD.Console.PrintMessage("der Kopf mit math rtan: " + str(rtan) + "\n") Pnt0 = Base.Vector(0.0,0.0,0.0) Pnt1 = Base.Vector(dk_mean/2.0,0.0,0.0) Pnt2 = Base.Vector(dk_mean/2.0,0.0,-cham) Pnt3 = Base.Vector(dia/2.0+r-r*math.cos(rad45),0.0,-k-rtan+r*math.sin(rad45)) # Arc-points Pnt4 = Base.Vector(dia/2.0+r-r*(math.cos(rad225)),0.0,-k-rtan+r*math.sin(rad225)) Pnt5 = Base.Vector(dia/2.0,0.0,-k-rtan) #FreeCAD.Console.PrintMessage("last Arc point: " + str(-k-rtan) + "\n") Pnt6 = Base.Vector(dia/2.0,0.0,-a_real) edge1 = Part.makeLine(Pnt0,Pnt1) edge2 = Part.makeLine(Pnt1,Pnt2) edge3 = Part.makeLine(Pnt2,Pnt3) #FreeCAD.Console.PrintMessage("before bolt points: " + str(cham) + "\n") # bolt points PntB1 = Base.Vector(dia/2.0,0.0,-l-P) PntB2 = Base.Vector(0.0,0.0,-l-P) #PntB3 = Base.Vector(0.0,0.0,-l)

edgeArc = Part.Arc(Pnt3,Pnt4,Pnt5).toShape edgeArc1 = Part.makeLine(Pnt3,Pnt4) edgeArc2 = Part.makeLine(Pnt4,Pnt5) edge6 = Part.makeLine(Pnt5,Pnt6) edgeB0 = Part.makeLine(Pnt6,PntB1) edgeB1 = Part.makeLine(PntB1,PntB2) #edgeB2 = Part.makeLine(PntB2,PntB3) edgeZ0 = Part.makeLine(PntB2,Pnt0) aWire=Part.Wire([edge1,edge2,edge3,edgeArc,edge6, \         edgeB0, edgeB1, edgeZ0]) #Part.show(aWire) aFace =Part.Face(aWire) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) #FreeCAD.Console.PrintMessage("der Kopf mit revolve: " + str(dia) + "\n") #Parameter for slot-recess: dk_theo, n_min, offset, t_mean slot = Part.makePlane(dk_theo, n_min, \         Base.Vector(dk_theo/2.0,-n_min/2.0,0.0),Base.Vector(0.0,0.0,-1.0)) slot = slot.extrude(Base.Vector(0.0,0.0,-t_mean)) head = head.cut(slot)

if self.RealThread.isChecked: # cut the thread head = self.cutIsoThread(head, dia, P, turns, l)     cyl = Part.makeCylinder(dia/2.0,P,Base.Vector(0.0,0.0,-l-P),Base.Vector(0.0,0.0,1.0),360) head = head.cut(cyl) return head

# make ISO 4762 Allan Screw head def makeIso4762(self,ThreadType ='M6',l=25.0): dia=float(ThreadType.lstrip('M')) #FreeCAD.Console.PrintMessage("der 4762Kopf mit l: " + str(l) + "\n") P, b, dk_max, da, ds_mean, e, lf, k, r, s_mean, t, v, dw, w = iso4762def[ThreadType] #FreeCAD.Console.PrintMessage("der Kopf mit iso r: " + str(r) + "\n") sqrt2_ = 1.0/math.sqrt(2.0) e_cham = 2.0 * s_mean / math.sqrt(3.0) depth = s_mean / 3.0

if (b > l - 3*P): bmax = l-3*P else: bmax = b     turns = round((bmax+P)/P) # number of thread turns a_real = l-turns*P # starting point of thread #rad30 = math.radians(30.0) #Head Points Pnt0 = Base.Vector(0.0,0.0,k-e_cham/2.0) #Center Point for chamfer Pnt1 = Base.Vector(e_cham/2.0,0.0,k)    #inner chamfer edge at head Pnt2 = Base.Vector(dk_max/2.0-v,0.0,k)  #start of fillet Pnt3 = Base.Vector(dk_max/2.0-v+v*sqrt2_,0.0,k-v+v*sqrt2_) #arc-point of fillet Pnt4 = Base.Vector(dk_max/2.0,0.0,k-v)  #end of fillet Pnt5 = Base.Vector(dk_max/2.0,0.0,(dk_max-dw)/2.0) #we have a chamfer here Pnt6 = Base.Vector(dw/2.0,0.0,0.0)          #end of chamfer Pnt7 = Base.Vector(dia/2.0+r,0.0,0.0)    #start of fillet between head and shank Pnt8 = Base.Vector(dia/2.0+r-r*sqrt2_,0.0,-r+r*sqrt2_) #arc-point of fillet Pnt9 = Base.Vector(dia/2.0,0.0,-r)       # end of fillet Pnt10 = Base.Vector(dia/2.0,0.0,-a_real)       # start of thread edge1 = Part.makeLine(Pnt0,Pnt1) edge2 = Part.makeLine(Pnt1,Pnt2) edge3 = Part.Arc(Pnt2,Pnt3,Pnt4).toShape edge4 = Part.makeLine(Pnt4,Pnt5) edge5 = Part.makeLine(Pnt5,Pnt6) edge6 = Part.makeLine(Pnt6,Pnt7) edge7 = Part.Arc(Pnt7,Pnt8,Pnt9).toShape edge8 = Part.makeLine(Pnt9,Pnt10) # bolt points PntB1 = Base.Vector(dia/2.0,0.0,-l-P) # ISO4762 wants a chamfer here!!! PntB2 = Base.Vector(0.0,0.0,-l-P) #PntB3 = Base.Vector(0.0,0.0,-l)

edgeB0 = Part.makeLine(Pnt10,PntB1) edgeB1 = Part.makeLine(PntB1,PntB2) #edgeB2 = Part.makeLine(PntB2,PntB3) edgeZ0 = Part.makeLine(PntB2,Pnt0) aWire=Part.Wire([edge1,edge2,edge3,edge4,edge5,edge6,edge7,edge8, \         edgeB0, edgeB1, edgeZ0]) aFace =Part.Face(aWire) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) # The round part of the cutting tool, we need for the allan hex PntH1 = Base.Vector(0.0,0.0,k) PntH2 = Base.Vector(e_cham/2.0,0.0,k) PntH3 = Base.Vector(e_cham/2.0,0.0,k-t) PntH4 = Base.Vector(0.0,0.0,k-t-depth) edgeH1 = Part.makeLine(PntH1,PntH2) edgeH2 = Part.makeLine(PntH2,PntH3) edgeH3 = Part.makeLine(PntH3,PntH4) edgeH4 = Part.makeLine(PntH4,PntH1) hWire=Part.Wire([edgeH1,edgeH2,edgeH3,edgeH4]) #Part.show(hWire) hFace =Part.Face(hWire) roundtool = hFace.revolve(Base.Vector(0.0,0.0,k),Base.Vector(0.0,0.0,1.0),360)

extrude = self.makeHextool(s_mean, k, dk_max) #Part.show(extrude) hextool = roundtool.cut(extrude) #FreeCAD.Console.PrintMessage("der Kopf geschnitten: " + str(dia) + "\n") allenscrew = head.cut(hextool)

if self.RealThread.isChecked: # cut the thread allenscrew = self.cutIsoThread(allenscrew, dia, P, turns, l)     cyl = self.cutChamfer(dia, P, l)      #cyl = Part.makeCylinder(dia/2.0,P,Base.Vector(0.0,0.0,-l-P),Base.Vector(0.0,0.0,1.0),360) allenscrew = allenscrew.cut(cyl) return allenscrew

# make ISO 7380 Button head Screw def makeIso7380(self,ThreadType ='M6',l=25.0): dia=float(ThreadType.lstrip('M')) FreeCAD.Console.PrintMessage("der 7380-Kopf mit l: " + str(l) + "\n") P, a, da, dk, dk_mean,s_mean, t_min, r, k, e, w = iso7380def[ThreadType] FreeCAD.Console.PrintMessage("der Kopf mit iso r: " + str(r) + "\n") sqrt2_ = 1.0/math.sqrt(2.0) e_cham = 2.0 * s_mean / math.sqrt(3.0) depth = s_mean / 3.0 #ak = -(k**2 + e_cham**2-dk**2)/(2*k) ak = -(4*k**2 + e_cham**2 - dk**2)/(8*k) rH = math.sqrt((dk/2.0)**2 + ak**2) #alpha = (math.atan((k + ak)/e_cham) + math.atan(ak/dk))/2 alpha = (math.atan(2*(k + ak)/e_cham) + math.atan((2*ak)/dk))/2 turns = round((l-1.1*P)/P) # number of thread turns a_real = l-turns*P # starting point of thread FreeCAD.Console.PrintMessage("Value ak: " + str(ak) + "\n") #Head Points Pnt0 = Base.Vector(0.0,0.0,k-e_cham/2.0) #Center Point for chamfer Pnt1 = Base.Vector(e_cham/2.0,0.0,k)    #inner chamfer edge at head Pnt2 = Base.Vector(rH*math.cos(alpha),0.0,-ak + rH*math.sin(alpha)) #arc-point of button Pnt3 = Base.Vector(dk/2.0,0.0,0.0)  #end of fillet Pnt4 = Base.Vector(dia/2.0+r,0.0,0.0)    #start of fillet between head and shank Pnt5 = Base.Vector(dia/2.0+r-r*sqrt2_,0.0,-r+r*sqrt2_) #arc-point of fillet Pnt6 = Base.Vector(dia/2.0,0.0,-r)       # end of fillet Pnt7 = Base.Vector(dia/2.0,0.0,-a_real)       # start of thread

FreeCAD.Console.PrintMessage("Points made, rH: " + str(rH) + "\n")

edge1 = Part.makeLine(Pnt0,Pnt1) edge2 = Part.Arc(Pnt1,Pnt2,Pnt3).toShape edge3 = Part.makeLine(Pnt3,Pnt4) edge4 = Part.Arc(Pnt4,Pnt5,Pnt6).toShape edge5 = Part.makeLine(Pnt6,Pnt7) # bolt points PntB1 = Base.Vector(dia/2.0,0.0,-l-P) # ISO7380 wants a chamfer here!!! PntB2 = Base.Vector(0.0,0.0,-l-P)     # we chamfer with the last cut!!! #PntB3 = Base.Vector(0.0,0.0,-l)

edgeB0 = Part.makeLine(Pnt7,PntB1) edgeB1 = Part.makeLine(PntB1,PntB2) edgeZ0 = Part.makeLine(PntB2,Pnt0) aWire=Part.Wire([edge1,edge2,edge3,edge4,edge5, \         edgeB0, edgeB1, edgeZ0]) #Part.show(aWire) aFace =Part.Face(aWire) #Part.show(aFace) head = aFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) #Part.show(head) # The round part of the cutting tool, we need for the allan hex PntH1 = Base.Vector(0.0,0.0,k) PntH2 = Base.Vector(e_cham/2.0,0.0,k) PntH3 = Base.Vector(e_cham/2.0,0.0,k-t_min) PntH4 = Base.Vector(0.0,0.0,k-t_min-depth) edgeH1 = Part.makeLine(PntH1,PntH2) edgeH2 = Part.makeLine(PntH2,PntH3) edgeH3 = Part.makeLine(PntH3,PntH4) edgeH4 = Part.makeLine(PntH4,PntH1) hWire=Part.Wire([edgeH1,edgeH2,edgeH3,edgeH4]) Part.show(hWire) hFace =Part.Face(hWire) roundtool = hFace.revolve(Base.Vector(0.0,0.0,k),Base.Vector(0.0,0.0,1.0),360)

extrude = self.makeHextool(s_mean, k, dk) Part.show(extrude) hextool = roundtool.cut(extrude) FreeCAD.Console.PrintMessage("der Kopf geschnitten: " + str(dia) + "\n") buttonscrew = head.cut(hextool)

if self.RealThread.isChecked: # cut the thread buttonscrew = self.cutIsoThread(buttonscrew, dia, P, turns, l)     cyl = self.cutChamfer(dia, P, l)      #cyl = Part.makeCylinder(dia/2.0,P,Base.Vector(0.0,0.0,-l-P),Base.Vector(0.0,0.0,1.0),360) buttonscrew = buttonscrew.cut(cyl) return buttonscrew

def makeHextool(self,s_hex, k_hex, cir_hex): # makes a cylinder with an inner hex hole, used as cutting tool # create hexagon mhex=Base.Matrix mhex.rotateZ(math.radians(60.0)) polygon = [] vhex=Base.Vector(s_hex/math.sqrt(3.0),0.0,0.0) for i in range(6): polygon.append(vhex) vhex = mhex.multiply(vhex) polygon.append(vhex) hexagon = Part.makePolygon(polygon) # create circle circ=Part.makeCircle(cir_hex/2.0) # Create the face with the circle as outline and the hexagon as hole face=Part.Face([Part.Wire(circ),hexagon]) # Extrude in z to create the final cutting tool exHex=face.extrude(Base.Vector(0.0,0.0,k_hex)) return exHex

def cutTooliso261(self, d, P, angle = False): # P pitch of thread, d nonminal diameter of thread (floats) H=P*math.cos(math.radians(30)) # H depth of thread r=d/2.0  #Nominal radius # points for screw cutting profile ps1 = (r + H/16.0,0.0,-P/2.0+P/32.0) ps2 = (r-H*5.0/8.0,0.0,-P/8.0) ps3 = (r-H*17.0/24.0,0.0,0.0) # Center of Arc ps4 = (r-H*5.0/8.0,0.0,+P/8.0) ps5 = (r+ H/16.0,0.0,+P/2.0-P/32.0)

edge1 = Part.makeLine(ps1,ps2) edge2 = Part.Arc(FreeCAD.Vector(ps2),FreeCAD.Vector(ps3),FreeCAD.Vector(ps4)).toShape edge3 = Part.makeLine(ps4,ps5) edge4 = Part.makeLine(ps5,ps1)

alpha_rad = math.atan(H*17.0/24.0/P) alpha = math.degrees(alpha_rad) Hyp = P/math.cos(alpha_rad) # Parameter for the last turn (angle==True) tuning = 0.42 if d>14: tuning = 0.40 # This works for a diameter of 6 # helix = Part.makeHelix(P,P,(d-H*26.0/24.0)/2.0,0) # make just one turn, length is identical to pitch if angle: helix = Part.makeHelix(Hyp,Hyp,d*tuning,alpha) # make just one turn, length is identical to pitch else: helix = Part.makeHelix(P,P,d*0.42,0) # make just one turn, length is identical to pitch cutProfile = Part.Wire([edge1,edge2,edge3,edge4]) makeSolid=1 isFrenet=1 pipe = Part.Wire(helix).makePipeShell([cutProfile],makeSolid,isFrenet) # Part.show(pipe) return pipe

def cutIsoThread(self, rawScrew, dia_cT, P_cT, turns_cT, l_cT): # Parameter object=head, dia, P, turns, l     FreeCAD.Console.PrintMessage("vor cutTool: " + str(dia_cT) + "\n") cutTool=self.cutTooliso261(dia_cT, P_cT, False) FreeCAD.Console.PrintMessage("cutTool made: " + str(dia_cT) + "\n") rotations = int(turns_cT) cutTool.Placement.Base = Base.Vector(0.0,0.0,-l_cT-P_cT/2.0) FreeCAD.Console.PrintMessage("cutTool placed: " + str(dia_cT) + "\n") for i in range(rotations): rawScrew = rawScrew.cut(cutTool) cutTool.Placement.Base = Base.Vector(0.0,0.0,-l_cT-P_cT/2.0+P_cT*(i+1.0)) lastCut = self.cutTooliso261(dia_cT, P_cT, True) lastCut.Placement.Base = Base.Vector(0.0,0.0,-l_cT-P_cT/2.0+P_cT*(i+1.0)) threadedScrew = rawScrew.cut(lastCut) return threadedScrew

def cutChamfer(self, dia_cC, P_cC, l_cC): cham_t = P_cC*math.sqrt(3.0)/2.0*17.0/24.0 PntC0 = Base.Vector(0.0,0.0,-l_cC) PntC1 = Base.Vector(dia_cC/2.0-cham_t,0.0,-l_cC) PntC2 = Base.Vector(dia_cC/2.0,0.0,-l_cC+cham_t) PntC3 = Base.Vector(dia_cC/2.0,0.0,-l_cC-P_cC) PntC4 = Base.Vector(0.0,0.0,-l_cC-P_cC) edgeC1 = Part.makeLine(PntC0,PntC1) edgeC2 = Part.makeLine(PntC1,PntC2) edgeC3 = Part.makeLine(PntC2,PntC3) edgeC4 = Part.makeLine(PntC3,PntC4) edgeC5 = Part.makeLine(PntC4,PntC0) CWire=Part.Wire([edgeC1,edgeC2,edgeC3,edgeC4,edgeC5]) CFace =Part.Face(CWire) cyl = CFace.revolve(Base.Vector(0.0,0.0,0.0),Base.Vector(0.0,0.0,1.0),360) return cyl

class screw: d = QtGui.QWidget d.ui = Ui_ScrewMaker d.ui.setupUi(d) d.show