' ' Automatically create threads and taps from the user defined standard set ' from a file "std_thread_database.csv" ' ' Author: Amji Ramanujam ' Organization: Engineering Geometry Systems ' Date: 11/06/06 ' Copyright (c) 2006, Engineering Geometry Systems ' ' General Description: ' This macro lets the user to maintain his own list of standard threads. ' This macro looks for a csv file in the same directory as this macro is stored in. ' The filename must be "std_thread_database.csv" ' A dialog appears from where the user can choose his standard thread from a list. ' Metric threads can be added to the database by adding rows to the "std_thread_database.csv" file. ' When a metric thread is added the "Dimensions" column must be "mm" and instead of TPI, pitch must be specified. Option Explicit Type StdThread s_desg As String s_dim As String s_major As Double s_minor As Double s_pitch As Variant s_length As Double s_od_height As Double s_id_height As Double s_angle As Double End Type Dim threadList() As StdThread Dim doc As FMDocument Dim OD_thread As Boolean Dim prev_val As Integer 'Sub main Public Sub AddThread Dim inp_filename As String Dim F As String inp_filename = "std_thread_database.csv" OD_thread = True prev_val = 0 ChDir MacroDir F = Dir$(inp_filename) If F = "" Then inp_filename = GetFilePath$(,"csv;txt",,"Open Thread list file",0) End If Open inp_filename For Input As #1 ReDim threadList(0) Dim N As Integer Dim ListArray() As String ReDim ListArray(0) Dim e_msg As String Dim t_thread As FMTurnThread Dim t_tap As FMHole Dim m_thread As FMThreadMilling Dim m_tap As FMHole Dim tmp_header As String Set doc = ActiveDocument Line Input #1, tmp_header While Not EOF(1) N = UBound(threadList)+1 ReDim Preserve threadList(N) ReDim Preserve ListArray(N) Input #1, threadList(N-1).s_desg, threadList(N-1).s_dim,threadList(N-1).s_major, threadList(N-1).s_minor, threadList(N-1).s_pitch, threadList(N-1).s_length, threadList(N-1).s_od_height, threadList(N-1).s_id_height, threadList(N-1).s_angle ListArray(N-1) = threadList(N-1).s_desg If InStr(UCase(threadList(N-1).s_dim),"IN") Then threadList(N-1).s_pitch = 1/(threadList(N-1).s_pitch) End If If doc.Metric = True Then If InStr(UCase(threadList(N-1).s_dim),"IN") Then threadList(N-1).s_major = threadList(N-1).s_major * 25.4 threadList(N-1).s_minor = threadList(N-1).s_minor * 25.4 threadList(N-1).s_pitch = threadList(N-1).s_pitch * 25.4 threadList(N-1).s_length = threadList(N-1).s_length * 25.4 threadList(N-1).s_od_height = threadList(N-1).s_od_height * 25.4 threadList(N-1).s_id_height = threadList(N-1).s_id_height * 25.4 End If Else If InStr(UCase(threadList(N-1).s_dim),"MM") Then threadList(N-1).s_major = threadList(N-1).s_major / 25.4 threadList(N-1).s_pitch = threadList(N-1).s_pitch / 25.4 threadList(N-1).s_length = threadList(N-1).s_length / 25.4 threadList(N-1).s_od_height = threadList(N-1).s_od_height / 25.4 threadList(N-1).s_id_height = threadList(N-1).s_id_height / 25.4 End If End If Wend Close #1 'ListArray() = threadList().desg Begin Dialog UserDialog 760,497,.DialogFunc ' %GRID:10,7,1,1 Text 90,196,90,14,"Major Dia",.Text5 Text 100,84,50,14,"Type",.Text1 OptionGroup .f_type OptionButton 260,35,120,14,"Thread",.OptionButton1 OptionButton 430,35,120,14,"Tapped Hole",.OptionButton2 OptionGroup .th_type OptionButton 160,77,90,14,"ID",.ID OptionButton 160,98,90,14,"OD",.OD OptionGroup .th_dir OptionButton 490,91,130,14,"Right Handed",.RH OptionButton 490,70,110,14,"Left Handed",.LH Text 420,84,60,14,"Thread",.Text2 DropListBox 250,154,260,147,ListArray(),.DropListBox1 Text 250,133,190,14,"Thread Designation",.Text3 TextBox 80,217,110,21,.dia TextBox 260,217,110,21,.pitch_t TextBox 420,217,110,21,.length_t TextBox 590,217,110,21,.height_t Text 270,196,90,14,"Pitch",.Text4 Text 420,196,120,14,"Thread Length",.Text6 Text 590,196,120,14,"Thread Height",.Text7 TextBox 350,280,90,21,.angle_t Text 360,259,80,14,"Angle",.Text8 CancelButton 440,427,90,21 TextBox 160,357,90,21,.X TextBox 360,357,90,21,.Y TextBox 530,357,90,21,.Z Text 140,359,20,14,"X:",.Text9 Text 340,359,20,21,"Y:",.Text10 Text 510,359,20,14,"Z:",.Text11 OKButton 220,427,90,21 End Dialog Dim thread_dlg As UserDialog thread_dlg.DropListBox1 = 0 thread_dlg.th_type = 1 thread_dlg.th_dir = 0 If OD_thread Then thread_dlg.dia = Str(CCur(threadList(0).s_major)) Else thread_dlg.dia = Str(CCur(threadList(0).s_minor)) End If thread_dlg.pitch_t = Str(CCur(threadList(0).s_pitch)) thread_dlg.length_t = Str(CCur(threadList(0).s_length)) If OD_thread Then thread_dlg.height_t = Str(CCur(threadList(0).s_od_height)) Else thread_dlg.height_t = Str(CCur(threadList(0).s_id_height)) End If thread_dlg.angle_t = Str(CCur(threadList(0).s_angle)) thread_dlg.X = "0.0" thread_dlg.Y = "0.0" thread_dlg.Z = "0.0" thread_dlg.f_type = 0 Dialog thread_dlg If doc.ActiveSetup.Type = eST_Turning Then If thread_dlg.f_type =0 Then Set t_thread = doc.Features.AddTurnThread(thread_dlg.th_type , thread_dlg.th_dir, Val(thread_dlg.dia) ,Val(thread_dlg.pitch_t), Val(thread_dlg.length_t),Val(thread_dlg.height_t),Val(thread_dlg.angle_t),Val(thread_dlg.Z) , e_msg , True) Else Set t_tap = doc.Features.AddTurnHole(eHT_TappedHole,Val(thread_dlg.X),Val(thread_dlg.Y),Val(thread_dlg.Z), Val(thread_dlg.dia),Val(thread_dlg.length_t),False,0, Val(thread_dlg.angle_t), , ,Val(thread_dlg.length_t)-0.25,Val(thread_dlg.pitch_t),True, e_msg,True) End If ElseIf doc.ActiveSetup.Type = eST_Milling Then If thread_dlg.f_type = 0 Then Set m_thread = doc.Features.AddThreadMilling(thread_dlg.th_type ,thread_dlg.th_dir, Val(thread_dlg.dia) ,Val(thread_dlg.pitch_t), Val(thread_dlg.length_t),Val(thread_dlg.height_t),Val(thread_dlg.angle_t),Val(thread_dlg.X), Val(thread_dlg.Y),Val(thread_dlg.Z), e_msg , True) Else Set m_tap = doc.Features.AddHole(eHT_TappedHole,Val(thread_dlg.X),Val(thread_dlg.Y),Val(thread_dlg.Z), Val(thread_dlg.dia),Val(thread_dlg.length_t),False,0, Val(thread_dlg.angle_t), , ,Val(thread_dlg.length_t)-0.25,Val(thread_dlg.pitch_t),True, e_msg,True) End If End If If e_msg <> "" Then MsgBox "Error:" & e_msg & " Check if the database has the required parameter." End If End Sub Public Function DialogFunc%(DlgItem$, Action%, SuppValue%) Select Case Action% Case 1 'When the dialog is initialized (pops up) If (doc.ActiveSetup.Type = eST_Turning) Then DlgVisible "X",False DlgVisible "Y",False DlgVisible "Text9",False DlgVisible "Text10",False End If Case 2 ' Value changing or button pressed Select Case DlgItem$ Case "DropListBox1" If OD_thread Then DlgText "dia",Str(CCur(threadList(SuppValue).s_major)) Else DlgText "dia",Str(CCur(threadList(SuppValue).s_minor)) End If DlgText "pitch_t",Str(CCur(threadList(SuppValue).s_pitch)) DlgText "length_t",Str(CCur(threadList(SuppValue).s_length)) If OD_thread Then DlgText "height_t",Str(CCur(threadList(SuppValue).s_od_height)) Else DlgText "height_t",Str(CCur(threadList(SuppValue).s_id_height)) End If DlgText "angle_t",Str(CCur(threadList(SuppValue).s_angle)) prev_val =SuppValue DialogFunc% = True 'do not exit the dialog Case "th_type" If SuppValue = 0 Then DlgText "Text5","Minor Dia" OD_thread = False Else DlgText "Text5","Major Dia" OD_thread = True End If 'Now updating the text boxes If OD_thread Then DlgText "dia",Str(CCur(threadList(prev_val).s_major)) Else DlgText "dia",Str(CCur(threadList(prev_val).s_minor)) End If DlgText "pitch_t",Str(CCur(threadList(prev_val).s_pitch)) DlgText "length_t",Str(CCur(threadList(prev_val).s_length)) If OD_thread Then DlgText "height_t",Str(CCur(threadList(prev_val).s_od_height)) Else DlgText "height_t",Str(CCur(threadList(prev_val).s_id_height)) End If DlgText "angle_t",Str(CCur(threadList(prev_val).s_angle)) DialogFunc% = True 'do not exit the dialog Case "Cancel" Exit All End Select End Select End Function