Tapatalk

G code highlighting

G code highlighting

1
NewbieNewbie
1

PostJul 23, 2007#1

Hello all,

I have been using UltraEdit for years to edit G code for manufacturing.

How do I get this thing to highlight G0 in Green and  Z-.75 in red, etc.

Here is example of my code:

Code: Select all

% 2VSH32160_MACHINE      ,MX--,
;POSTED    :07/06/07 16:55:49, BY: BRENT 
;CUSTOMER  : 
;EP        : 
;PROGRAM # : 
;PROGRAMMER: BRENT  
;(OPERATOR MESSAGES HERE) 
G53 
G48 S0 
G90 
;G29Y;  Y TABLE INDEPENDANT 
;G28YV;    V TABLE INDEPENDANT 
G51 E.003
N1 T8
N2 M6
N3 D8

N4 S15000 M3
N5 G0 X59.418 Y-23.375 Z7.5072 A90.0 C0.0
N6 Y-20.85 Z7.5072
N7 G1 Y-20.75 F50.0
N8 X61.6868 Z5.1009
N9 X63.4441 Z5.0962
N10 X65.2158 Y-20.75 Z5.0994
N11 X67.0238 Z5.1105
N12 X68.8744 Z5.1299
N13 X70.7844 Y-20.75 Z5.1579
N14 X72.7887 Z5.1953
N15 X74.9415 Z5.2432
N16 X76.3234 Z5.2776
N17 X78.8413 Z5.3524
N18 X81.2952 Z5.4331
N19 X83.6686 Y-20.75 Z5.519
N20 X85.4493 Z5.5887
N21 X85.4727 Z5.5897
N22 Z5.5897
N23 X86.2958 Z5.6235
N24 X87.1554 Z5.7088
N25 X89.4892 Z5.8065
N26 Z5.8065
N27 X93.6409 Z5.9775
N28 X97.7581 Y-20.75 Z6.1549
N29 X97.7848 Z6.1559
N30 X99.4257 Z6.2107
N31 X99.6104 Z6.2181
N32 X99.752 Z6.2246
N33 X100.2391 Z6.1983
N34 X100.2992 Z6.1995
N35 X100.3384 Z6.2016
N36 X103.7716 Y-20.75 Z6.3633
N37 X106.9396 Z6.5197
N38 X109.8978 Z6.6731
N39 X112.6328 Z6.822
N40 X113.3357 Z6.8653
N41 X114.0594 Z6.9179
N42 X114.8108 Z6.9807
N43 X115.5915 Y-20.75 Z7.0541
N44 X116.1138 Z7.1075
N45 G0 Y-23.375 Z7.1075
N46 X58.5085 Y-23.375 Z6.6497
N47 Y-20.85 Z6.6497
N48 G1 Y-20.75
N49 X61.1445 Z3.8539
N50 X62.9208 Z3.8468
N51 X64.6908 Y-20.75 Z3.8476
N52 X66.4889 Z3.8564
N53 X68.3267 Z3.8733
N54 X70.2215 Y-20.75 Z3.8987
N55 X72.19 Z3.9331
N56 X74.2934 Z3.9777
N57 X76.3572 Z4.0281
N58 X78.8769 Z4.1029
N59 X81.3328 Z4.1837
N60 X83.7084 Y-20.75 Z4.2696
N61 X85.5008 Z4.3398
N62 X85.5251 Z4.3408
N63 Z4.3408
N64 X86.3836 Z4.3761
N65 X87.2431 Z4.4614
N66 X89.542 Z4.5576
N67 Z4.5576
N68 X93.6977 Z4.7288
N69 X97.8132 Y-20.75 Z4.9061
N70 X97.8132 Z4.9062
N71 X99.469 Z4.9614
N72 X99.6674 Z4.9694
N73 X99.7469 Z4.973
N74 X100.2335 Z4.9468
N75 X100.3238 Z4.9496
N76 X100.344 Z4.9495
N77 X100.365 Z4.9502
N78 X100.3425 Z4.9495
N79 X100.3959 Z4.9529
N80 X103.8302 Y-20.75 Z5.1147
N81 X106.9996 Z5.2712
N82 X109.9594 Z5.4246
N83 X112.7025 Z5.574
N84 X113.4132 Z5.6177
N85 X114.1442 Z5.6707
N86 X114.901 Z5.7338
N87 X115.6863 Y-20.75 Z5.8074
N88 X116.2449 Z5.8644
N89 G0 Y-23.375 Z5.8644
Z20.0 
M5 
G0 X0 Y0 A0 C0 F1200 
G48S0
M0 
G53
G0Z0.
G0X0.Y0.A0.C0
M30
Thanks in advance
Mace

6,826625
Grand MasterGrand Master
6,826625

PostJul 24, 2007#2

You can start with the Mill G Code - 04/14/99 syntax highlighting wordfile.

Move your mouse pointer over the menu Resources at top of the UltraEdit homepage and next over the submenu Extra downloads and click on Wordfiles with primary (left) mouse button.

At top of this page you will find some instructions how to add the content of a wordfile you can download on this page to the wordfile you currently use.

The date of the wordfile for "G code" makes clear that this wordfile is old and surely does not enable all the enhanced syntax highlighting feature of the latest versions of UltraEdit.

The wordfiles are written by users like you and are sent to UltraEdit, Inc. which host it without really testing it. Why? Because for testing/updating a wordfile big knowledge about the syntax of the highlighted language and good example files are necessary. You can't suppose that UltraEdit, Inc. really has the knowledge and example files for all the languages for which wordfiles exist.

UltraEdit, Inc. highly welcomes contributions from users. So, if you have high knowledge about "G code" and lots of example files, please improve the really old wordfile for "G code" and when finished send it to UltraEdit, Inc. My macro set to sort the keywords of a syntax highlighting definition, find duplicate words and find invalid words will be maybe a help for you - see the ultimate syntax highlighting tools.

If you need further help to create the improved syntax highlighting wordfile for "G code", post here your questions and I will try my best to answer it and help you.

There is a big help page titled Syntax Highlighting in help of UltraEdit which explains what you can use for syntax highlighting and how to create your own language definition.

A user has written also a Template for syntax highlighting language wordfile which you can also use.

There are also some power tips about syntax highlighting wordfiles.

1
NewbieNewbie
1

PostAug 08, 2007#3

Hi,

Try the following which works pretty well for me:

Code: Select all

/L13"NC Files" Nocase Line Comment = $ Block Comment On = ( Block Comment Off = ) File Extensions = ISO NC CNC
/Delimiters = Q( )=+*
/Function String = "%[%+O+:]*"  
/C1"G-Codes"
** G  
/C2"M-Codes"
** M 
/C3"Rotary and Linear Positioning"
** A B C U V W X Y Z  
/C4"Angle, Radius"
** I J K R  
/C5"Speeds and Feeds"
** F S
/C6"Line-Numbers, Tools"
** N T
/C7"Radius-, Length-Offsets"
** D H
/C8"Other stuff" 
** % : E L O
Just go to Advanced - Configuration - Editor display - Syntax highlighting, open the wordfile and paste the above code at the end of the file. Make sure that no other language in the file uses the /L13 number, or alter the /L number for NC Files to the next free number.

Save the wordfile: then, while still in the Syntax highlighting configuration window, choose NC files from the Language drop down list, and go through the Color Groups for the NC language, altering colors to taste.

Have fun!

Rob

2

PostJan 18, 2022#4

I have conducted the above procedure and it doesn't seem to work when switching to View as language: Mill G-Codes

How do you alter the color groups?

How can I strip all the N numbers from the beginning of each line as in Masc's code?

Code: Select all

/L1"Mills G-Codes" Line Comment = // Block Comment On = /* Block Comment Off = */ Escape Char = \ String Chars = "' File Extensions = C CPP CC H HPP AWK
/Delimiters = ~!@%^&*()-+=|\/{}[]:;"'<> , .?
/Function String = "%[a-zA-Z_]*)"
/Indent Strings = "{"
/Unindent Strings = "}"
/C1
G40 G41 G42 G68 G69 G70 G71 G90 G91 G92 G93 G94 G99
/C2
G00 G04
/C3
G01
/C4
G02 G03
/C5
G17 G18 G19
/C6
M00 M01 M02 M03 M04 M05 M06 M07 M08 M09 M13 M14 M19 M26 M60
/C7
G80 G81 G82 G83 G84

/L13"NC Files" Nocase Line Comment = $ Block Comment On = ( Block Comment Off = ) File Extensions = ISO NC CNC
/Delimiters = Q( )=+*
/Function String = "%[%+O+:]*"
/C1"G-Codes"
** G
/C2"M-Codes"
** M
/C3"Rotary and Linear Positioning"
** A B C U V W X Y Z
/C4"Angle, Radius"
** I J K R
/C5"Speeds and Feeds"
** F S
/C6"Line-Numbers, Tools"
** N T
/C7"Radius-, Length-Offsets"
** D H
/C8"Other stuff"
** % : E L O

6,826625
Grand MasterGrand Master
6,826625

PostJan 18, 2022#5

Well, there have been changes regarding to syntax highlighting wordfiles and syntax highlighting configuration in the last 14 years. So I have to assume first that you are using at the moment the currently latest UltraEdit for Windows v28.20 and not a 14 year olds version of UltraEdit.

In ribbon mode click on ribbon tab View in first group Display on the check box item Line numbers to get the display of the line numbers removed. In toolbar/menu mode with contemporary menus click in menu View on menu item Line numbers. In toolbar/menu mode with traditional menus click in menu View on menu item Display line numbers.

There are no longer up to 20 syntax highlighting languages defined inside one wordfile as 14 years ago. There can be used nowadays a not limited number of wordfiles stored in the wordfiles directory configured at Advanced - Settings or Configuration - Editor display - Syntax highlighting which is by default %APPDATA%\IDMComp\UltraEdit\wordfiles each containing just one language definition. I strongly recommend to split up your single wordfile with two language definitions into two wordfiles, one with the language definition Mills G-Codes with file name G-Codes.uew and another one with language definition NC Files with file name NC.uew and store both uew files in the wordfiles directory. The language number after /L does not really matter anymore as no longer used by UltraEdit.

The syntax highlighting colors for the two languages can be configured after a restart of UltraEdit in the Manage Themes dialog window on third tab Syntax after selecting the language Mills G-Codes respectively NC Files. In ribbon mode click on ribbon tab Layout in first group Look and feel on second item Themes. In toolbar/menu mode with contemporary menus click in menu Layout in submenu Themes on first menu item Manage themes. In toolbar/menu mode with traditional menus click in menu View in submenu Themes on first menu item Manage themes.

2

PostJan 18, 2022#6

Using:
UltraEdit Text/Hex Editor (x64) 
Version 28.00.0.68

Not the UltraEdit Line Numbers in the left  margin but, the NC code line numbers. i.e. N1 to N89  

From : N89 G0 Y-23.375 Z5.8644
To: G0 Y-23.375 Z5.8644 (for every line)

Splitting wordfile into two files allow for new language selection.

Text coloring is not allowing for enough detail.

I.e. when given:

Code: Select all

N1185T23
N1190M6
N1195T36
N1200M1
N1205G90G0G40G80
N1210M140
N1215G54.1P22
N1220M3S2000
N1225G0B-180.
N1230X1.2182Y14.6041
N1235G43Z15.8437H23
I may want:

T23 Brown
H23 Brown
S2000 Green
M1 Blue
N1230X1.2182Y14.6041  want X1.2182 Y14.6041  and maybe just X red and the 1.2182 Black with spaces between the 2 & Y

Maybe that's why there are specific Text Editors for CNC Programmers which my company is not willing to provide.

6,826625
Grand MasterGrand Master
6,826625

PostJan 19, 2022#7

I suggest to use either an UltraEdit macro stored with a hotkey assigned for execution by key stored in a macro file which is configured to be automatically loaded on startup or an UltraEdit script with an assigned hotkey added to the scripts list containing the code to run a regular expression replace all from top of the file to remove the NC code line numbers. It is also possible that a macro is executed on every open of a file which runs the regular expression replace depending on the file extension already on opening an NC file.

Macro code:

Code: Select all

InsertMode
ColumnModeOff
Top
UltraEditReOn
Find MatchCase RegExp "%N[0-9]+[^t ]++"
Replace All ""
Script code:

Code: Select all

if (UltraEdit.document.length > 0)  // Is any file opened?
{
   // Define environment for this script.
   UltraEdit.insertMode();
   // The next line is for UltraEdit for Windows.
   if (typeof(UltraEdit.columnModeOff) == "function") UltraEdit.columnModeOff();
   // This line is for UltraEdit for Linux and Mac.
   else if (typeof(UltraEdit.activeDocument.columnModeOff) == "function") UltraEdit.activeDocument.columnModeOff();

   // Move caret to top of the active file.
   UltraEdit.activeDocument.top();

   // Define the parameters for a case-sensitive UltraEdit regular expression
   // replace all removing from top of the file to end of the file from the
   // beginning of each line the character N and one or more digits and zero
   // or more tabs or spaces.
   UltraEdit.ueReOn();
   UltraEdit.activeDocument.findReplace.mode=0;
   UltraEdit.activeDocument.findReplace.matchCase=true;
   UltraEdit.activeDocument.findReplace.matchWord=false;
   UltraEdit.activeDocument.findReplace.regExp=true;
   UltraEdit.activeDocument.findReplace.searchDown=true;
   if (typeof(UltraEdit.activeDocument.findReplace.searchInColumn) == "boolean")
   {
      UltraEdit.activeDocument.findReplace.searchInColumn=false;
   }
   UltraEdit.activeDocument.findReplace.preserveCase=false;
   UltraEdit.activeDocument.findReplace.replaceAll=true;
   UltraEdit.activeDocument.findReplace.replaceInAllOpen=false;
   UltraEdit.activeDocument.findReplace.replace("%N[0-9]+[^t ]++","");
}
The line starting with /Delimiters = defines the word delimiters. The characters between two word delimiters are words which can be added to the color groups to be highlighted with the color associated with the color group. The delimiters itself are interpreted also as single character words. It is possible to define in the color groups a word of which first character is a word delimiter. ** at beginning of a line in a color group defines substrings to highlight which means all words starting with the space separated strings on same line in the wordfile whereby the first character can be a word delimiter too.

Example:

Code: Select all

/C2"M-Codes"
** M
The second color group with name M-Codes of syntax highlighting language NC Files highlights all words beginning with the non-word delimiting character M. The color blue must be configured in the Manage Themes dialog window on tab Syntax for color group M-Codes of the language NC Files. There must be a word delimiting character left to M-Codes which can be either a newline character or one of the characters defined in the wordfile on line starting with /Delimiters =.

So it is of course necessary to get all NC code line numbers removed or a space inserted after all NC code line numbers to get M1 displayed with blue color instead of the color assigned to the color group Line-Numbers, Tools which is for highlighting all words starting with N or T.

The color group Speeds and Feeds highlights all words starting with F or S.

It is up to you which color group highlights which words. You have to define the substrings in the wordfile for NC Files just like you want it and configure the colors you want for each color group.

The macro/script can be extended to run more regular expression replaces:

Additional macro code:

Code: Select all

Find MatchCase RegExp "^(X-++[0-9.]+^)Y"
Replace All "^1 Y"
Additional script code:

Code: Select all

   // Insert a space character between X and Y values.
   UltraEdit.activeDocument.findReplace.replace("^(X-++[0-9.]+^)Y","^1 Y");