586,312 active members*
3,244 visitors online*
Register for free
Login
Page 1 of 2 12
Results 1 to 20 of 23
  1. #1
    Join Date
    Jul 2003
    Posts
    1220

    Question Editing G-Code File

    Hi. I have a G-Code file which I want to alter the Z approach feed speed from the clearance height of Z20.
    There are about 200 of these approaches and I'm looking for an easy way to alter the code.
    The code I have is similar to this.

    G01 Z3 F50
    G01 Z0 F1200

    And would like to alter to this.

    G00 Z3 (G01 altered to G00 and F50 dropped to next line)
    F50
    G01 Z0 (F1200 dropped to next line)
    F1200

    Is there any Text Editor Programs that will do this or will I need to write a text macro?
    Thanks.

  2. #2
    Join Date
    Jul 2009
    Posts
    419
    You can use "find and replace" which is available in most editors. You can replace them all at once, which may also replace ones you do not want replaced or line by line, one at a time.

    Find and replace is usually available in the "edit" menu.
    Sven
    http://www.puresven.com/?q=building-cnc-router

  3. #3
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by CaptainVee View Post
    You can use "find and replace" which is available in most editors.....
    Thanks Captain.
    Not sure 'Find and Replace' will do what I want.
    The code is full of G01 and I have no way of selecting only the line with the F50. The Z value varies so that cannot be included in the Find.
    Also, I don't think 'Find and Replace' will paste the F50/F1200 to a new line.

    Edit. added pic of some code.
    Attached Thumbnails Attached Thumbnails Code1.JPG   Code1.JPG  

  4. #4
    Join Date
    Jul 2009
    Posts
    419
    I tried it with selecting the whole line of the old then start "replace".

    Type out the way you want it to be somewhere outside the code, including returns. Copy that and paste that in the "replace with" field.

    The return is not visible in the field but does get used during replacing, at least when I tried it in Kate (linux texteditor).

    I seem to recall that in wordperfect 8 I used this same trick...

    Edit: Oh, just now read the line about varying Z height.

    Could you pm me part of the code you use with a small explanation of what you need?
    Sven
    http://www.puresven.com/?q=building-cnc-router

  5. #5
    Join Date
    Jun 2003
    Posts
    205

  6. #6
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by CaptainVee View Post
    ......Could you pm me part of the code you use with a small explanation of what you need?
    Hi, Tried to send PM but appears your P/Box is blocked.

  7. #7
    Join Date
    Dec 2012
    Posts
    395
    Hi Kiwi,

    It can be done with a spreadsheet like Microsoft Excel.
    Insert the hole nc-code in one column.
    First you find/replace all F50's by lets say F5000 ore more instead off G00.
    Then replace all F1200 by F50.
    In the second column you put F1200 only at the lines with G1 X --- Z.
    You have to do this only a few times (4) and than you select (the cells) and drag it down to the last line, important, start sellecting the first cell under the first F1200.
    Now you select the 2 columns from top to bottom and copy it into f.e. Notepad or an other editor, than past and save.
    Iff it don't work send me your nc-code to PM and I do it for you.

    Regards,
    Heavy_Metal
    The Netherlands.

  8. #8
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by Heavy_Metal View Post
    It can be done with a spreadsheet like Microsoft Excel.....
    Hi HeavyMetal. Thanks for your help. I tried to follow your instructions but couldn't get it to work.
    I managed to convert using excel with different steps with good results.
    Here is my procedure.

    1. Import G-Code text file into Excel using Delimited and Space to create columns.
    2. Insert two new columns 'A' & 'B'.
    3. Number lines in column A and enter '1' in all B cells to end of file.
    4. Sort file by column 'E'
    5. Copy all lines with F50 and F1200 and paste at end of file on spread sheet.
    6. In column B, of the pasted lines change the '1' to '2' .
    7. Delete the contents of column 'C' and 'D' of the pasted lines
    8. Change the G01 to G00 in column 'C' in the original lines with F50 (at the top of the spread sheet.)
    9. Delete all the F1200 and F50 in the original lines.
    10. Sort by 'A'
    11. Delete Columns 'A' & 'B'
    12. Save as CSV file.
    13. Open as text file and delete all commas.
    Attached Thumbnails Attached Thumbnails 123.jpg   456.jpg   456.jpg   456.jpg  

    789.jpg   123.jpg   456.jpg   789.jpg  

    123.jpg   456.jpg  

  9. #9
    Join Date
    Dec 2012
    Posts
    395

    Editing

    Hi Kiwi,

    Ok, the way you solved the problem is not so easy and not without risks when you sorted columns in Excel.
    I assume you don't have a CAD/CAM-system to make a new nc-code.

    I explain how I handle the problem, this time I started like you did, a 3 column spreadsheet, attachment Test-1.jpg.

    I clicked on column A and inserted a new column (A), then deleted column B with only G0 and G1 data, attachment Test-2.jpg.
    With find/replace you have to find [F50] and replace is with an [ empty field ], put no data to it and it will remove the F50.
    Now find the F1200 and replace it by F50.
    In column A you put G0 in the lines with Z22. ( repeat 3 times, thats enough ).
    In column A you put G1 in the lines with the new F50 Z-plunge feed ( also repeat 3 times ).

    Put F1200 in the right lines, attachment Test-3.jpg.
    Select cells (column A) from just under first G1 and drag down to last lines off your program (almost).
    Also for F1200 (column D)

    Select your cells to the last line and copy text to an editor like Notepad or Wordpad, attachment Test-4.jpg.

    Save your nc-code to txt-file or nc-file, attachment Test-5_6 and 7.jpg, the white-spaces or not important for your cnc-control .
    If you want to remove them you have to use an editor like Cimco-Edit wich has the option [ Remove Whitespaces ].
    When you send the data back from your machine to PC they (spaces) are also removed.

    Maybe you can try this option to see iff it works.

    Regards,
    Heavy_Metal
    The Netherlands.
    Attached Thumbnails Attached Thumbnails Test-7.jpg  

  10. #10
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by Heavy_Metal View Post
    ....Ok, the way you solved the problem is not so easy and not without risks when you sorted columns in Excel.
    I assume you don't have a CAD/CAM-system to make a new nc-code......
    Hi Heavy_Metal, Thanks for your input.
    I have an old version (V21) of BobCad which I like because I can play with the paths on the screen and then generate the code from this.
    On this job I have altered the path on the screen so the tool path climb mills down one side, jumps over to the other side and climb mills back to the start end.
    My problem is, it wont generate the move from Z22 to Z3 as G0. See attached pics.

    Tried your method and couldn't get it to work.
    The file has 22500 lines with 90 Z moves to the clearance level. These move are not evenly spaced though out the program. Spacing varies between 160 and 200 lines so dragging the G0's, G1's and F1200 don't line up with the relevant lines.
    I've attached the txt file if you care to have a look. Thanks again for your help.
    Attached Files Attached Files

  11. #11
    Join Date
    Aug 2011
    Posts
    2517
    I've needed to do similar things in the past on large NC programs. For example changing a program from X- to X and G02 to G03 and G03 to G02 and I- to I and I to I-. This is when a program is written for a lathe with a rear turret that is in X minus but another machine is to use the same program and the X's need to be positive. There's a huge possibility a search/replace would mess up the program so I have found doing it manually gets me what I want exactly without any errors, or I just re-program it again. Editing 200 lines would take just a few minutes to fix. I think you wasted more time than that typing here explaining your problem ;-)

  12. #12
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by fordav11 View Post
    ..... Editing 200 lines would take just a few minutes to fix. I think you wasted more time than that typing here explaining your problem ;-)
    The 200 lines are hidden in a file of 22500 lines. I certainly couldn't modify the file in a few minutes like you.
    The procedure that I used does not use find and replace.
    Thanks for your negative input.

  13. #13
    Join Date
    Aug 2011
    Posts
    2517
    ok well I missed the part about 22500 lines ;-)

    with a selective search/replace the carriage return/line feed code can be added to the replace (what CaptainVee talks about). In MS Word it's ^p

    search (without quotes) "G01 Z3"
    replace (without quotes) "G01 Z3 ^p"
    F50 automatically drops to next line because of the above added ^p (carriage return/linefeed)

    when you do a search/replace a box comes up and you don't click 'replace all' but instead select specific lines and monitor those changes by clicking 'replace' or 'ignore' or 'skip' or something similar depending on the program being used.

    I've done this many times in the past and it works well. but you have to watch the searched line and then decide whether to replace or skip. even so it'd still be pretty quick doing it this way.

  14. #14
    Join Date
    Feb 2006
    Posts
    338
    Do what computer programers would, use a good code text editor with regular expression search and replace.
    Notepad++ Home A free one that is pretty good.
    Ultraedit is another and possibly better but is payed.

    There are also addons for highlighting g-code that greatly help readability.

    You will need to read up on RegEx (regular expression) for an example Mark's Speechblog: Notepad++: A guide to using regular expressions and extended search mode
    A sample search/replace for you might be
    Search: G01 Z(0-9\.\-) F50\r\nG01 Z(0-9\.\-) F
    Replace: G00 Z\1\r\n F50\r\n G01 Z\2\r\n F

  15. #15
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by fordav11 View Post
    ......with a selective search/replace the carriage return/line feed code can be added to the replace (what CaptainVee talks about). In MS Word it's ^p

    search (without quotes) "G01 Z3"
    replace (without quotes) "G01 Z3 ^p"
    F50 automatically drops to next line because of the above added ^p (carriage return/linefeed)......
    I tried CaptainVee's suggestion but couldn't get it to work with the programs I have, notepad and MSword. I also tried using Chr(13) & Chr(10)
    I didn't know about ^p. (Pleased to learn something new.)
    I'm not sure this will work in this case as the Z value changes.

  16. #16
    Join Date
    Feb 2006
    Posts
    338
    Quote Originally Posted by dpuch View Post
    A sample search/replace for you might be
    Search: G01 Z(0-9\.\-) F50\r\nG01 Z(0-9\.\-) F
    Replace: G00 Z\1\r\n F50\r\n G01 Z\2\r\n F
    Oops realized I forgot some stuff in the above and there may be other errors, always test search/replace. ESPECIALLY RegEx
    Search: G01 Z(0-9\.\-)+ F50\r\nG01 Z(0-9\.\-)+ F
    Replace: G00 Z\1\r\n F50\r\n G01 Z\2\r\n F

    Also a brief explanation
    Z(0-9\.\-)+ matches Z followed by any combination of 0-9 . or - the + matches more than one occurrence
    \r\n is carriage return and linefeed (or vice versa I always forget which order) AKA a new line
    In the replace \1 matches what was in the first set of () and \2 the second ect.

  17. #17
    Join Date
    Jul 2003
    Posts
    1220
    Thanks dpuch. I hadn't heard of NotePad++ before. It sounds like a very handy program. I had previously tried a program called GAWK which is good to do this type of task but runs under DOS which I could never remember the commands.
    I'll down load NotePad++ and study how to use it.
    Even though I have solved my problem, it's always interesting to know how other would do it.
    Thanks for your help.

  18. #18
    Join Date
    Aug 2011
    Posts
    2517
    there's many special characters that can be searched/replaced the same way.....

    Paragraph mark
    Type ^p or ^13

    Tab character
    Type ^t or ^9

    ASCII character
    Type ^nnn, where nnn is the character code

    ANSI character
    Type ^0nnn, where 0 is zero and nnn is the character code

    Caret character
    Type ^^

    Manual line break
    Type ^l or ^11

    Column break
    Type ^n or ^14

    Page or section break
    Type ^12 (when replacing, inserts a page break)

    Manual page break
    Type ^m

    Nonbreaking space
    Type ^s

    Nonbreaking hyphen
    Type ^~

    Any character
    Type ^?

    Any digit
    Type ^#

    Any letter
    Type ^$

    Unicode character
    Type ^Unnnn where nnnn is the character code

    Em space (Unicode)
    Type ^u8195

    En space (Unicode)
    Type ^u8194

    White space
    Type ^w (any combination of regular and nonbreaking spaces, and tab characters)


    See the Word help file for more info.

  19. #19
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by fordav11 View Post
    there's many special characters that can be searched/replaced the same way.....
    I had a quick look in MSWord, but couldn't see how to find values of different lengths (number of figures eg 23.55 or 3.222) and also use the same figure in the replace.
    Will need to do a lot more research.

  20. #20
    Join Date
    Jul 2003
    Posts
    1220
    Quote Originally Posted by dpuch View Post
    Oops realized I forgot some stuff in the above and there may be other errors, always test search/replace. ESPECIALLY RegEx
    Search: G01 Z(0-9\.\-)+ F50\r\nG01 Z(0-9\.\-)+ F
    Replace: G00 Z\1\r\n F50\r\n G01 Z\2\r\n F........................
    Hi, I tried the code but was unable to get it to complete the task.
    Would only find when brackets were sqr style '[]' and the 1 & 2 wouldn't print the values.
    Not sure what is wrong?

Page 1 of 2 12

Similar Threads

  1. Need help editing asc post file for Esprit.
    By Den Man in forum Esprit
    Replies: 8
    Last Post: 06-14-2020, 10:02 PM
  2. opeing G code file for editing
    By billwann in forum SheetCam
    Replies: 0
    Last Post: 11-18-2011, 04:31 PM
  3. Editing free g-code file????
    By fsa in forum PTC Pro/Manufacture
    Replies: 1
    Last Post: 11-01-2010, 04:35 PM
  4. Editing FANUC GPP File
    By almo0797 in forum SolidCAM for SolidWorks and SolidCAM for Inventor
    Replies: 6
    Last Post: 07-13-2009, 11:31 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •