Author Topic: Erase "M02" lines in CNC file  (Read 4533 times)

0 Members and 1 Guest are viewing this topic.

Offline patrydufTopic starter

  • Premier Member
  • *****
  • Posts: 1154
  • Country: ca
  • Gender: Male
Erase "M02" lines in CNC file
« on: Feb 27, 2023, 19:28:10 PM »
I have this code I'm working on with some help from a friend.
I want to erase all of the "M02" (End of Program) lines in the NC file, except the last one, of course...
It is a combine NC file, but somehow, the post process writes an (End of Program) line after each (End of Sheet) line.

Here's the code:

Code: [Select]
Requires TASK.Selection
 dim cncPath = "C:\Fabrication\DataBases\CF Metric 2017 - Rev3\CNC"
dim filename = "999-31105.cnc"

dim fileScan as FILELOCATOR

fileScan.Scan(cncPath, filename, true, false)

dim lp = 1
dim currentLine = ""

for lp = 1 to fileScan.FileCount
  Object ncFile = new FILE(fileScan.File[lp], FORINPUT+ISTEXT)
  Object newNcFile = new FILE(cncPath + "!999-31105.cnc", FOROUTPUT+ISTEXT)
  newNcFile.Open()
  while not ncFile.EOF
    currentLine = ncFile.ReadLine()
Debug currentLine
    if currentLine <> "M02" then
      newNcFile.WriteLine(currentLine)
    EndIf
      EndWhile
  ncFile.Close()
  newNcFile.Position = FILE_END
  newNcFile.WriteLine("M02")
  newNcFile.Close()
REM-  ncFile.Delete(TRUE)
next lp

The probleme I have, is the original file is read as expected, but the newfile is nowhere to be found.
Looks like it is not written at all.
I refreshed the folder, but it is simply not there.

Certainly, I'm missing something.
Any small bit of help would be greatly appreciated.
Thank you all,
"Whether you think you can or you can't - YOU'RE RIGHT."
"Que vous croyiez pouvoir ou non - VOUS AVEZ RAISON."

Yvon Dufresne - Novybec
CADmep, CAMduct, Revit, eVolve

Offline patrydufTopic starter

  • Premier Member
  • *****
  • Posts: 1154
  • Country: ca
  • Gender: Male
Re: Erase "M02" lines in CNC file
« Reply #1 on: Feb 28, 2023, 11:53:18 AM »
OK,
"We" found it...
There was a "\" missing at the end of the path.
The file was in the parent folder.
"Whether you think you can or you can't - YOU'RE RIGHT."
"Que vous croyiez pouvoir ou non - VOUS AVEZ RAISON."

Yvon Dufresne - Novybec
CADmep, CAMduct, Revit, eVolve