smoe years ago i did something simular for G43 should be easy to modify this
' ---------------------------------------------------------------------------------
' TPS 02/2018
' macro to open GCode file and comment out all G43
' ---------------------------------------------------------------------------------
Sub Main()
On Error GoTo errhandler
'get the source file
Dim Filename As String
Dim Dialog1
Set Dialog1 = CreateObject("MSComDlg.CommonDialog")
Dialog1.MaxFileSize = 256
Dialog1.Filter = "GCode Files (*.tap)|*.tap"
Dialog1.FilterIndex = 1
Dialog1.DialogTitle = "select GCode file"
Dialog1.InitDir = GetUserLabel(200)
Dialog1.CancelError = True
'get the last selection
Dialog1.FileName = ""
save = false
If save = true Then
Dialog1.DefaultExt = def
Dialog1.Flags = &H800 + &H4
discard = Dialog1.ShowSave()
Else
Dialog1.Flags = &H1000 + &H4 + &H800
discard = Dialog1.ShowOpen()
End If
FileName = Dialog1.FileName
If Len(FileName) = 0 Then
message "no source file selected"
Exit Sub
End If
'store last selection
SetUserLabel(200,CurDir)
'find the last "\" in filename
For i = 1 To Len(FileName)
If Mid(FileName,i,1) = "\" Then
last = i
End If
Next i
'extract filename
myfilename = Mid(FileName,last+1,Len(FileName)-last)
'get the destination folder
Dim destfile As String
Dialog1.DialogTitle = "select destination folder and filename"
'get the last selection
Dialog1.FileName = GetUserLabel(201) + "\" + myfilename
Dialog1.InitDir = GetUserLabel(201)
save = true
If save = true Then
Dialog1.DefaultExt = def
Dialog1.Flags = &H800 + &H4
discard = Dialog1.ShowSave()
Else
Dialog1.Flags = &H1000 + &H4 + &H800
discard = Dialog1.ShowOpen()
End If
destfile = Dialog1.FileName
If Len(destfile) = 0 Then
message "no destination file selected"
Exit Sub
End If
'store last selection
SetUserLabel(201,CurDir)
'open input file
FNumInput = FreeFile 'Determine next file number.
Open FileName For Input As FNumInput
'open output file
FNumOutput = FreeFile 'Determine next file number.
Open "C:\Mach3\GCode\import.txt" For Output As FNumOutput
actions = 0
'go through To whole file
Do While Not EOF(FNumInput)
Line Input #FNumInput, FileData ' Read a line of data.
If ((InStr(FileData,"G43") <> 0) And (Left(FileData,1) <> "(")) Then
Print #FNumOutput, "( " + FileData + " )"
actions = actions + 1
Else
Print #FNumOutput, FileData
End If
Loop
Close ' Close all open files.
message CStr(actions) + " G43 have been found"
DoOEMButton(169) 'close Mach3 files just in case
SourceFile = "C:\Mach3\GCode\import.txt"
FileCopy SourceFile, destfile ' Copy source to target.
Kill SourceFile
LoadFile( destfile)
Exit Sub
errhandler:
message "user cancel"
End Sub