'*****************************************************************************
Private Const PI = 3.1415927
Private Const degtorad = 0.0174532
Sub screw()
'default 1/2 inch UNC 13 threads per inch
Dim strP As String
strP = InputBox("Pitch", "Screw Thread", 0.076923, 100, 100)
Dim strD As String
strD = InputBox("Blank Diameter", "Screw Thread", 0.5, 100, 100)
Dim strFA As String
strFA = InputBox("Flank Angle DEG", "Screw Thread", 30, 100, 100)
draw_screw True, 1#, CDbl(strP), CDbl(strD), CDbl(strFA)
End Sub
Private Function draw_screw(RightHanded As Boolean, Length As Double, Pitch As Double, OD As Double, flankAngle As Double) As Long
Dim rotang As Double
Dim P As Double 'pitch
Dim theta As Double 'flank angle
Dim S2 As Double 'Depth of truncation of triangular height at root
Dim S1 As Double 'Depth of truncation of triangular height at crest
Dim r2 As Double 'Root radius
Dim r1 As Double 'crest radius
Dim E As Double 'Effective Diameter
Dim n As Double 'Number of starts
Dim D As Double 'Major Diameter
Dim dmin As Double 'Minor Diameter
Dim h As Double 'height of thread
'D = E + 0.5 * P * cot(theta) - 2 * S1
'dmin = E - 0.5 * P * cot(theta) + 2 * S2
'h = 0.5 * P * cot(theta) - (S1 + S2)
D = OD
theta = flankAngle
P = Pitch
h = P / (2 * Tan(theta * degtorad))
dmin = D - 2 * h
rotang = (Length / P) * 360
Dim App As Application
Dim ActDr As Drawing
Dim Grs As Graphics
Dim gr As Graphic
Dim Gr1 As Graphic
Dim Ver As Vertex
Set App = IMSIGX.Application
Set ActDr = App.ActiveDrawing
Set Grs = ActDr.Graphics
Set gr = Grs.Add(, "TCW40SPIN") '
gr.Properties("$ROTATIONANGLE") = rotang 'deg
gr.Properties("$STEP") = P + P * 0.0001 'pitch
If RightHanded = True Then gr.Properties("$HANDINESS") = 0 Else gr.Properties("$HANDINESS") = 1
gr.Properties("$COILNUMBER") = rotang / 360 'number of coils
'screw axis
Set Ver = gr.Vertices.Add(0, 0, 0)
Set Ver = Nothing
Set Ver = gr.Vertices.Add(100, 0, 0)
Set Ver = Nothing
Set Gr1 = Grs.Add(, "polyline")
Set Ver = Gr1.Vertices.Add(0, dmin * 0.5, 0)
Set Ver = Nothing
Set Ver = Gr1.Vertices.Add(P * 0.5, D * 0.5, 0)
Set Ver = Nothing
Set Ver = Gr1.Vertices.Add(P, dmin * 0.5, 0)
Set Ver = Nothing
Set Ver = Gr1.Vertices.AddClose
Set Ver = Nothing
Set Gr1 = Grs.Remove(Gr1.Index)
gr.Graphics.AddGraphic Gr1
gr.RotateAxis PI / 2, 0, -1000, 0, 0, 1000, 0
'gr.MoveRelative 0, 0, -3
draw_screw = gr.ID
Set Gr1 = Nothing
Set gr = Nothing
Set Grs = Nothing
Set ActDr = Nothing
Set App = Nothing
End Function
'****************************************************************************]