Page 1 of 1

End of gcode finder

PostPosted: Mon Mar 21, 2022 8:36 pm
by Jpryder5
So we are in the process of switching from mach3 to uccnc and one function I made was a macro that found the end of a gcode file's line number so that it can be used to calculate the percentage of the file ran, but I'm struggling to find any way to convert this to C# with uccnc's context. I've already figured out how to write the percentage itself but this little bit of code stumps me.
Mach3 code (Visual Basic):
Code: Select all
DoOemButton(216)
Dim I
Dim textLine

Open FileName For Input As #1
//loads file and increments through each line until the end of file is found
   While Not EOF(1)
      Line Input #1, textLine
      I = I + 1
      SetuserDro(1202, I)
   Wend

Close #1
//writes the end line number to a user dro to be used and displayed elsewhere
Call SetUserDRO(1200,I)

Anyone with any ideas on how to do this in uccnc?

Re: End of gcode finder

PostPosted: Mon Mar 21, 2022 10:24 pm
by dezsoe
Try this:

Code: Select all
// ================================================================================================
// Count lines in g-code file
// ================================================================================================

string fileName = exec.Getgcodefilename();

if ((fileName == "") || (fileName == Application.StartupPath + "\\Contents\\Empty.txt"))
{
   exec.AddStatusmessage("No file loaded!");
   if (exec.GetLED(54)) // Cycle is started
      exec.Callbutton(130); // Cycle Stop
   return;
}

int LineCount = System.IO.File.ReadAllLines(fileName).Length;

exec.AddStatusmessage("Lines in file: " + LineCount.ToString());

Re: End of gcode finder

PostPosted: Thu Mar 24, 2022 8:19 pm
by Jpryder5
Sorry for the super late response, but it works much better than what I had used in mach3 thank you so much!