' Creates user input dialogs associated with each setup. ' inserts user text in nc code if post contains proper pseudo reserved word ' ' Author: Kyle Kershaw ' Organization: Engineering Geometry Systems ' Date: 8/9/2003 ' Copyright (c) 2003, Engineering Geometry Systems ' ' General Description ' ' This macro create a user input dialog box associated with each setup in a part document. ' ' The contents of the dialog are inserted in the NC code where the psuedo reserved word "SETUP-INFO" ' is found. ' ' The psuedo reserved words must be found within the first 15 lines of the program And are typically ' used in the Program Start format. If the psuedo word is not found, no changes are made to the NC code. ' ' The comment characters are gleaned from the characters surrounding the pseudo reserved words. ' For example, (SETUP-INFO) will output info surrounded by parenthesis ( ) ' 'SETUP-INFO' will output info surrounded by quotes ' ' ' do not include spaces between comment characters and pseudo reserved word ' Option Explicit Dim found_search_word As Boolean, buffer As String, temp_file_name As String Dim strt_char As String, end_char As String Public Sub SetupNotes Dim dialog_title As String, setup_info As String If TypeName( Application.ActiveDocument ) = "IFMDocument" Then 'do if it is an fm document Dim doc As FMDocument, Setup As FMSetup Set doc = Application.ActiveDocument Set Setup = doc.ActiveSetup dialog_title = Setup.Name setup_info = Setup.UserAttribute("setup_info") Else ' do if a mf or tsf document Dim Mdoc As MFGDocument Set Mdoc = Application.ActiveDocument dialog_title = Mdoc.Name setup_info = Mdoc.UserAttribute("setup_info") End If Begin Dialog UserDialog 570,294,"Setup information for Setup: " + dialog_title ' %GRID:10,7,1,1 TextBox 20,14,520,238,.TextBox1,1 OKButton 340,266,90,21 CancelButton 450,266,90,21 End Dialog If setup_info = "" Then ' modify this section for default setup info setup_info = "Customer name: " + vbCrLf + _ "Programed by: " + vbCrLf + _ "Origin X: " + vbCrLf + _ "Origin Y: " + vbCrLf + _ "Origin Z: " End If Dim dlg As UserDialog, result As Integer dlg.Textbox1 = setup_info result = Dialog( dlg ) If result = -1 Then ' OK button was pressed If TypeName( Application.ActiveDocument ) = "IFMDocument" Then Setup.SetUserAttribute( "setup_info", dlg.textbox1 ) Else Mdoc.SetUserAttribute( "setup_info", dlg.textbox1 ) End If End If End Sub Private Sub AddIn_OnConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) ' Bar name Button name Button face ID MakeButtonAndBar "SetupNotes", "SetupNotes", 23 End Sub Private Sub AddIn_OnDisConnect(ByVal flags As FeatureCAM.tagFMAddInFlags) HideDeleteBarButton "SetupNotes", "SetupNotes" End Sub Private Sub Application_PostNCCreate(doc As FeatureCAM.MFGDocument, _ ByVal nc_file_name As String, ByVal macro_file_cnt As Long, _ ByVal macro_file_names As Variant) SearchNcForWord(nc_file_name), "SETUP-INFO" AddSetupInfo(doc) CompleteRestOfFile(nc_file_name) End Sub Private Sub AddSetupInfo(doc As FeatureCAM.MFGDocument) Dim setup_info As String If TypeName( Application.ActiveDocument ) = "IFMDocument" Then setup_info = doc.ActiveSetup.UserAttribute( "setup_info" ) Else setup_info = doc.UserAttribute( "setup_info" ) End If buffer = UCase( setup_info ) Dim Lines() As String, n_lines As Integer, i As Integer Lines() = Split(buffer,vbCr + vbLf) n_lines = UBound(Lines) If (Lines(0) <> "") Then For i = 0 To n_lines Print #2, strt_char + " " + Lines(i) + " " + end_char Next i End If End Sub Private Sub SearchNcForWord(ByVal nc_file_name As String, ByVal search_word As String) ' get a temp file name Dim extension_index As Integer nc_file_name = UCase( nc_file_name) extension_index = InStrRev( nc_file_name, ".TXT") ' find file name temp_file_name = Left$( nc_file_name, extension_index-1) + ".tmp" ' add tmp extension ' open nc file and temp file as read and write Open nc_file_name For Input As #1 ' open the nc code for reading Open temp_file_name For Output As #2 ' open the tmp file for writing ' check for the search word in the first 15 lines of the file Dim i As Integer, strt_char_cnt As Integer, end_char_cnt As Integer found_search_word = False i=0 Do Line Input #1, buffer ' read line from nc code file, buffer = UCase( buffer) If( InStrRev( buffer, search_word) = 0) Then ' test for word in buffer string Print #2, buffer ' write to temp file Else found_search_word = True strt_char_cnt = InStr( buffer, search_word ) 'find start & end comment char If (strt_char_cnt = 1) Then strt_char = "" Else strt_char = Mid(buffer, strt_char_cnt-1,1) End If end_char_cnt = strt_char_cnt + Len( search_word ) end_char = Mid(buffer, end_char_cnt,1) Exit Do End If i=i+1 Loop While i<15 And Not EOF(1) End Sub Private Sub CompleteRestOfFile(ByVal nc_file_name As String) While Not EOF(1) Line Input #1,buffer Print #2, buffer Wend ' close files Close #1 Close #2 ' delete the nc code file and rename the tmp file so that it shows up in ' the nc code window If found_search_word Then Kill nc_file_name FileCopy( temp_file_name, nc_file_name) Kill temp_file_name Else Kill temp_file_name End If End Sub Private Sub MakeButtonAndBar(ByVal bar_name As String, ByVal button_name As String, _ ByVal button_id As Integer) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarBtn Set bars = Application.CommandBars Set bar = bars(bar_name) If bar Is Nothing Then Set bar = bars.Add(bar_name) Else bar.Visible = True End If Set ctrl = bar.Controls(button_name) If ctrl Is Nothing Then Set ctrl = bar.Controls.Add( ,,button_name) ctrl.FaceId = button_id bar.Visible = True End If End Sub Private Sub HideDeleteBarButton(ByVal bar_name As String, ByVal button_name As String) Dim bars As FMCmdBars, bar As FMCmdBar, ctrl As FMCmdBarCtrl Set bars = Application.CommandBars Set bar = bars(bar_name) If Not bar Is Nothing Then Set ctrl = bar.Controls(button_name) If Not ctrl Is Nothing Then If bar.Controls.Count > 1 Then ctrl.Delete Else bar.Visible=False End If End If End If End Sub