End of gcode finder

This is where you talk about Macros, show examples of your macro scripting and SHARE handy segments of script code as examples.

End of gcode finder

Postby Jpryder5 » Mon Mar 21, 2022 8:36 pm

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?
Jpryder5
 
Posts: 10
Joined: Tue Mar 08, 2022 10:05 pm

Re: End of gcode finder

Postby dezsoe » Mon Mar 21, 2022 10:24 pm

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());
dezsoe
 
Posts: 2093
Joined: Sun Mar 12, 2017 4:41 pm
Location: Csörög, Hungary

Re: End of gcode finder

Postby Jpryder5 » Thu Mar 24, 2022 8:19 pm

Sorry for the super late response, but it works much better than what I had used in mach3 thank you so much!
Jpryder5
 
Posts: 10
Joined: Tue Mar 08, 2022 10:05 pm


Return to Macros

Who is online

Users browsing this forum: No registered users and 5 guests