'#Reference {420B2830-E718-11CF-893D-00A0C9054228}#1.0#0#C:\WINDOWS\System32\scrrun.dll#Microsoft Scripting Runtime ' ' add stock tool list and setup sheet.bas - Write stock information,tool list and contents ' of setup sheet text file to the nc code. ' ' Author: Kyle Kershaw ' Organization: Engineering Geometry Systems ' Date: 12/1/02 1/29/03 ' Date: 1/29/03 added error handling for stock if multi fixture doc ' Date: 4/2/03 added ability to insert setup sheet text file. ' Date: 7/11/03 output only tools used in current setup ' Copyright (c) 2003, Engineering Geometry Systems ' ' General Description ' ' This macro gets stock information and list of tools used and adds them to the NC code. ' Also inserts the contents of a test file as setup sheet information. ' ' The stock info contains size, shape amd material and is inserted in the nc code ' where the psuedo reserved word "STOCK-DIMS" is found. ' ' The tool list contains the tool tool number, tool name, and tool comment ' and is inserted in the NC code where the psuedo reserved word "TOOL-LIST" ' is found. ' ' The contents of a text file named "{filename} setup sheet.txt" is inserted in the NC code where the psuedo reserved ' word "SETUP-SHEET" is found. For example; for caliper.fm, the file name should be "caliper setup sheet.txt" ' The macro looks for this file in the same folder as the .fm file. ' ' If the psuedo words are not found, no changes are made to the NC code for that object. ' ' The comment characters are gleaned from the characters surrounding the pseudo reserved words. ' For example, (STOCK-DIMS) will output info surrouded by parenthasis ( ) ' 'STOCK-DIMS' will output info surrouded by quotes ' ' ' ' ' 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 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), "STOCK-DIMS" AddStockInfo(Doc) CompleteRestOfFile(nc_file_name) SearchNcForWord(nc_file_name), "TOOL-LIST" AddToolInfo(Doc) CompleteRestOfFile(nc_file_name) SearchNcForWord(nc_file_name), "SETUP-SHEET" AddSetupInfo(Doc) CompleteRestOfFile(nc_file_name) 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 strt_char = Mid(buffer, strt_char_cnt-1,1) 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<30 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 AddStockInfo(Doc As FeatureCAM.MFGDocument) ' get stock information Dim stock As FMStock Dim stock_type As tagFMStockType Dim dLen As Double, dWidth As Double, dThick As Double, dDia As Double, dId As Double Dim locX As Double, locY As Double, locZ As Double Dim matrl As String On Error GoTo Errorhandler Set stock = Doc.Stock stock.GetDimensions stock_type, dLen, dWidth, dThick, dDia, dId stock.GetLocation locX, locY, locZ matrl = stock.Material If stock_type = eST_Block Then Print #2, strt_char +" BLOCK STOCK - "+ matrl + ". X" & CStr(dLen) + _ " Y" & CStr(dWidth) + " Z" & CStr(dThick) + " " + end_char ElseIf stock_type = eST_Round Then Print #2, strt_char +" ROUND STOCK - "+ matrl + ". OD " & CStr(dDia) + _ " ID " & CStr(dId) + " Z " & CStr(dLen) + " " + end_char End If Exit Sub Errorhandler: End Sub Private Sub AddToolInfo(Doc As FeatureCAM.MFGDocument) ' add tool info from toolmap object Dim tool As FMToolMap, oper As FMOperation For Each tool In Application.ActiveDocument.ToolMaps For Each oper In Application.ActiveDocument.Operations If Not (oper.Tool Is Nothing) Then If (tool.Tool = oper.Tool) Then Print #2, strt_char +" T" & CStr$(tool.ToolNumber) + " = " + UCase(tool.Tool) + _ " " + UCase(tool.Tool.Comment) + " " + end_char Exit For End If End If Next Next End Sub Private Sub AddSetupInfo(Doc As FeatureCAM.MFGDocument) Dim fso As New Scripting.FileSystemObject, doc_fullname As String, doc_name As String, _ doc_path As String, setup_sheet_fullname As String doc_fullname = Doc.FullName doc_name = fso.GetBaseName(doc_fullname) doc_path = Doc.Path setup_sheet_fullname = doc_path & "\" & doc_name & " setup sheet.txt" If fso.FileExists(setup_sheet_fullname) Then Open setup_sheet_fullname For Input As #3 ' open setup sheet as write While Not EOF(3) Line Input #3,buffer buffer = UCase( buffer) Print #2, strt_char + " " + buffer + " " + end_char Wend Close #3 End If End Sub