Need Help! position changes in G-code


Results 1 to 10 of 10

Thread: position changes in G-code

  1. #1
    Member
    Join Date
    Aug 2013
    Posts
    4
    Downloads
    0
    Uploads
    0

    Default position changes in G-code

    Hey machinists everywhere,

    I have written a relative work-intense G-code a while ago and now need one of the milled pockets to move to a different position within the XY coordinates. I first tried to implement a G92 command to simply add an offset to the position, but neither my CAM (Filou) nor my CNC controller software (WinPC NC) can handle the G92 command. But I anyway would rather change the values in the G-code directly than adding an offset, because in my world this can only lead to a lot of new problems....

    So what I search for is a software where I can put in a set of G-code and tell it:
    1. Search for the letter X (or Y)
    2. add the value "A" to the number after the letter
    3. search on

    So e.g. the program gets:
    N1 G1 X13 Y20
    N2 G1 X14 Y30

    and if I choose the X axis and "A" is -2 it returns:
    N1 G1 X11 Y20
    N2 G1 X12 Y30

    Does anybody see a solution for this?

    I do something similar when I want to change the Z height of an engraving. I copy the code into Microsoft Wordpad and use the "replace" command to change the Z-height for a set of G1 commands.

    position changes in G-code-rft-jpg

    But this only works because all Z values are identical. I would like to find a similar primitive-but-fast solution for a large number of commands with changing values after X or Y.

    thanks in advance from Germany
    Leotse

    Similar Threads:


  2. #2
    Member
    Join Date
    Dec 2012
    Location
    The Netherlands
    Posts
    356
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    Hey,

    You can use G54 - G59 or shift offset by G52 ( X - Y - Z ).
    If you can find Cimco Edit or an other good nc-code editor they can do the job for you.
    Cimco Edit has the [ Simple Math Function ] see picture.

    position changes in G-code-cimco_edit-simple-math-functions-jpg

    Last edited by Heavy_Metal; 10-28-2020 at 02:14 PM.


  3. #3
    Member
    Join Date
    Jan 2005
    Location
    USA
    Posts
    11662
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    Quote Originally Posted by leotse View Post
    Hey machinists everywhere,

    I have written a relative work-intense G-code a while ago and now need one of the milled pockets to move to a different position within the XY coordinates. I first tried to implement a G92 command to simply add an offset to the position, but neither my CAM (Filou) nor my CNC controller software (WinPC NC) can handle the G92 command. But I anyway would rather change the values in the G-code directly than adding an offset, because in my world this can only lead to a lot of new problems....

    So what I search for is a software where I can put in a set of G-code and tell it:
    1. Search for the letter X (or Y)
    2. add the value "A" to the number after the letter
    3. search on

    So e.g. the program gets:
    N1 G1 X13 Y20
    N2 G1 X14 Y30

    and if I choose the X axis and "A" is -2 it returns:
    N1 G1 X11 Y20
    N2 G1 X12 Y30

    Does anybody see a solution for this?

    I do something similar when I want to change the Z height of an engraving. I copy the code into Microsoft Wordpad and use the "replace" command to change the Z-height for a set of G1 commands.

    position changes in G-code-rft-jpg

    But this only works because all Z values are identical. I would like to find a similar primitive-but-fast solution for a large number of commands with changing values after X or Y.

    thanks in advance from Germany
    Leotse
    You can just use a simpleG1 X------ Y--------F---. move to where you want the pocket to be, or use another work offset G55 G0X----Y-----

    Mactec54


  4. #4
    Member machinehop5's Avatar
    Join Date
    Aug 2009
    Location
    United States
    Posts
    769
    Downloads
    2
    Uploads
    0

    Default Re: position changes in G-code

    ...write the Pocket/Program in Incremental G91 XY coordinates... then minor Editing to shift with G90 to move pocket anywhere you need possibility.



  5. #5
    Member lucaswalker's Avatar
    Join Date
    Sep 2018
    Posts
    19
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    In my opinion one of the reply above are cleaner, but if you really need the job to be done, use Notepad++

    Then :

    1) Install Python Script plugin from the Plugin Manager or from the official website.

    2) Then go to Plugins > Python Script > New Script. Choose a filename for your new file (eg add_numbers.py) and copy the code that follows:

    dx = 100.0
    dy = 100.0
    dz = 100.0

    def AddNumberToX(match):
    return 'X%s' % (str(float(match.group(1))+dx))

    def AddNumberToY(match):
    return 'Y%s' % (str(float(match.group(1))+dy))

    def AddNumberToZ(match):
    return 'Z%s' % (str(float(match.group(1))+dz))

    editor.rereplace('X([+-]?[0-9.]+)', AddNumberToX)
    editor.rereplace('Y([+-]?[0-9.]+)', AddNumberToY)
    editor.rereplace('Z([+-]?[0-9.]+)', AddNumberToZ)

    3) Run Plugins > Python Script > Scripts > add_numbers.py

    You may need to manage I and J for arc centers if they are not defined as relative to starting point !



  6. #6
    Member
    Join Date
    Aug 2013
    Posts
    4
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    Awesome, thanks a lot for all the suggestions. I try to figure that out.

    "machinehop5" : I tried the G91 incremental commands and it makes sense. I would not have access to the automated CAM functions in Filou as these use mostly G1-G3 commands. But for easy jobs and for my lathe this hint will be very helpful in the future, thanks.

    " Heavy_Metal" & " mactec54" : I tried to use the G52 and G54 commands but my CAM software can`t handle them, so I cannot see the results in my simulation, this seems to risky to me. Now I see WinPC-NC also can handle these, but in a newer version than I have....

    The Cimco simple-math-function editor is exactly what I imagined in my wildest dreams, but the software is quiet expensive. I will try the demo now, it surely has a lot of other things to offer.

    "lucaswalker" Wow, thanks for that. I did all that and now have the Python script. I didn't find out, how to process my G-code with the script. I put it into another txt file and let the script run as you said, but nothing happened...

    position changes in G-code-python-jpg

    Can you give me a hint what I am doing wrong?

    "You may need to manage I and J for arc centers if they are not defined as relative to starting point !" Luckily my program uses I and J relative to the start point. e.g.: N1 G2 X52.5 Y154 I-5 J0

    thanks
    Leotse



  7. #7
    Member lucaswalker's Avatar
    Join Date
    Sep 2018
    Posts
    19
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    Quote Originally Posted by leotse View Post
    Awesome, thanks a lot for all the suggestions. I try to figure that out.

    "machinehop5" : I tried the G91 incremental commands and it makes sense. I would not have access to the automated CAM functions in Filou as these use mostly G1-G3 commands. But for easy jobs and for my lathe this hint will be very helpful in the future, thanks.

    " Heavy_Metal" & " mactec54" : I tried to use the G52 and G54 commands but my CAM software can`t handle them, so I cannot see the results in my simulation, this seems to risky to me. Now I see WinPC-NC also can handle these, but in a newer version than I have....

    The Cimco simple-math-function editor is exactly what I imagined in my wildest dreams, but the software is quiet expensive. I will try the demo now, it surely has a lot of other things to offer.

    "lucaswalker" Wow, thanks for that. I did all that and now have the Python script. I didn't find out, how to process my G-code with the script. I put it into another txt file and let the script run as you said, but nothing happened...

    position changes in G-code-python-jpg

    Can you give me a hint what I am doing wrong?

    "You may need to manage I and J for arc centers if they are not defined as relative to starting point !" Luckily my program uses I and J relative to the start point. e.g.: N1 G2 X52.5 Y154 I-5 J0

    thanks
    Leotse
    Normally you just have to open your Gcode and then run the script :

    Attached Thumbnails Attached Thumbnails position changes in G-code-immagine-jpg  


  8. #8
    Member
    Join Date
    Aug 2013
    Posts
    4
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    I found the Python console and it returned this error message:

    Python 2.7.18 (v2.7.18:8d21aa21f2, Apr 20 2020, 13:19:08) [MSC v.1500 32 bit (Intel)]
    Initialisation took 172ms
    Ready.
    File "C:\Users\LeoBuero\AppData\Roaming\Notepad++\plugi ns\Config\PythonScript\scripts\Leo adds numbers to XY coordinates.py", line 6
    return 'X%s' % (str(float(match.group(1))+dx))
    ^
    IndentationError: expected an indented block
    I searched the web and could solve this by adding a "space" in front all three "return... lines, then it looked like this:
    position changes in G-code-python02-jpg

    And now it works, this is awesome. My pocket and the copied one with added X and Y values:
    position changes in G-code-python03-jpg
    Worktime: under one minute

    Thank you very much, this made my day and surely someone else can use this in the future. Have a great autumn.
    Leotse



  9. #9
    Member lucaswalker's Avatar
    Join Date
    Sep 2018
    Posts
    19
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    Oops, it lost identation when I copy/paste the code I guess, sorry for that.
    Im glad you have your solution !



  10. #10
    Member
    Join Date
    Aug 2013
    Posts
    4
    Downloads
    0
    Uploads
    0

    Default Re: position changes in G-code

    I attach the python script file

    Attached Files Attached Files


Tags for this Thread

Posting Permissions

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


About CNCzone.com

    We are the largest and most active discussion forum for manufacturing industry. The site is 100% free to join and use, so join today!

Follow us on


Our Brands

position changes in G-code

position changes in G-code

position changes in G-code