Hello Guest it is July 17, 2024, 01:10:54 PM

Author Topic: G-Code line numbering/removing - quick and dirty app  (Read 7935 times)

0 Members and 1 Guest are viewing this topic.

Offline Rimmel

  •  236 236
G-Code line numbering/removing - quick and dirty app
« on: July 29, 2014, 10:02:18 AM »
OK, so being very new to Mach3, G-Code and CNC in general - in recent months I have been experimenting with different CAM applications, Mach3 wizards and generally editing G-Code.

I've found that the mixture of the Mach3 Wizards, Cambam and manual splicing of the G-Code seems to work well for my small needs. However being new to it all, I have found that line numbers in the g-code for mach3 help a lot for finding little bugs in said g-code invaluable. But then manually editing the g-code messes up the numbering etc

With this in mind I looked around for a g-code line number adding and removal tool - but couldn't find one that wasn't part of a ¬£million suite  >:(

So I knocked up a quick application in C# VS2013 .Net framework 4.5 (took 30 mins).

1) Adds or removes line numbering in g-gode
2) It makes the changes in the text window only - until the SAVE button is pressed.
3) Ignores blank lines
4) Ignores comment lines - lines that start (.  e.g.   "( Toolchange )"
5) Supports .NC (cambam), .Tap and .txt files
6) Preloads numbers for formatting with zeros by counting how many lines are contained in the who g-code. e.g. if the g-code has 677 lines then that is 3 characters long. So the numbering would start "N001" to "N677". The two zeros are placed in the numbering to maintain formatting of the main code.
Example for 681 line code at start:
Code: [Select]
( Shuttle 7/28/2014 1:17:05 PM )
N001 G18 G21 G90 G91.1 G64 G40
N002 G94
N003 G0 Z50.0
N004 G0 X50.0
N005 M6 T0101 ( Tool 01)
N006 G0 Z1.0
N007 G0 X15.0
N008 M0 (STOP - Adjust workpiece)
N009 G0 Z50.0
N010 G0 X50.0
N011 G4 P2
N012 M3 S800
N013 M8
N014 G4 P3

N015 G0 Z0.8
N016 G0 X17.0
N017 G1 F8.0 X15.9
N018 G1 F50 X0
N019 G0 Z1.0
N020 G0 X17.0

Example for 681 line code at middle:
Code: [Select]
N090 G1 F50.0 Z-39.0287
N091 G0 X17.0
N092 G0 Z0.0
N093 G0 X15.6
N094 G1 F8.0 X15.4
N095 G1 F50.0 Z-0.2909
N096 G0 X17.0
N097 G0 Z-35.7987
N098 G0 X15.6
N099 G1 F8.0 X15.4
N100 G1 F50.0 Z-39.0234
N101 G0 X17.0
N102 G0 Z0.0
N103 G0 X15.5
N104 G1 F8.0 X15.3
N105 G1 F50.0 Z-0.2415
N106 G0 X17.0
N107 G0 Z-35.9302
N108 G0 X15.5
N109 G1 F8.0 X15.3
N110 G1 F50.0 Z-39.0181
N111 G0 X17.0
N112 G0 Z0.0
N113 G0 X15.4
N114 G1 F8.0 X15.2
N115 G1 F50.0 Z-0.198
N116 G0 X17.0
N117 G0 Z-36.0618
N118 G0 X15.4
N119 G1 F8.0 X15.2
N120 G1 F50.0 Z-39.0129
N121 G0 X17.0
N122 G0 Z0.0
N123 G0 X15.3

Example for 681 line code at end:
Code: [Select]
N659 G2 X16.0 Z-1.0 I-0.05 K-0.0021
N660 G1 Z-35.0
N661 G2 X15.9935 Z-35.0178 I-0.05 K0.0
N662 G1 X14.1 Z-37.5092
N663 G1 Z-38.955
N664 G1 X15.9105 Z-39.0503
( Finishing )
N665 S800
N666 G0 X17.0
N667 G0 Z0.1
N668 G0 X11.95
N669 G1 F8.0 Z0.0
N670 G1 F8.0 X11.8
N671 G1 F30.0 X13.8
N672 G2 X15.9 Z-1.0 I0.0061 K-1.0449
N673 G1 Z-35.0
N674 G1 X14.0 Z-37.5
N675 G1 Z-39.0
N676 G1 X15.9 Z-39.1
N677 G0 X50.0
N678 G0 Z50.0
N679 M5
N680 M9
N681 M30

If the g-code was 10789 lines long the numbering would start N00001. Like I say simply down for formatting the g-code for myself for easy reading. When the g-code is bug free I remove the numbering.

**** You will need the .Net framework 4.5 installed for this to work.
Unzip program, run, choose file, click add or remove line numbers - when happy click Save. If you don't click save the original file won't be changed.

Program reloads last .tap, .NC, .txt file automatically.

Quick and dirty:
This app doesn't use threading - didn't warrant the time being spent on it.
Minimum error checking - make sure the g-code file isn't in use in mach3 or other editor
Source code available if you want it - any bug just message me.

At your own risk  - blah blah blah - make backups of your g-code and don't moan to me if you lose a file.

Like I say I knocked it up for my use but you never know - someone might get some use out of it.


Offline Rimmel

  •  236 236
Re: G-Code line numbering/removing - quick and dirty app
« Reply #1 on: July 29, 2014, 10:04:43 AM »
Forum keep failingon adding the files.
« Last Edit: July 29, 2014, 10:06:39 AM by Rimmel »

Offline RICH

  • *
  •  7,427 7,427
Re: G-Code line numbering/removing - quick and dirty app
« Reply #2 on: July 30, 2014, 02:35:42 PM »
You may want to have a look at AutoEditNC for re-numbering of lines and it's free.

Re: G-Code line numbering/removing - quick and dirty app
« Reply #3 on: September 12, 2016, 08:36:30 PM »
can you please send to me the source code :) ?