584,837 active members*
5,785 visitors online*
Register for free
Login
Results 1 to 10 of 10
  1. #1
    Join Date
    Aug 2013
    Posts
    4

    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.

    Attachment 451298

    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

  2. #2
    Join Date
    Dec 2012
    Posts
    392

    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.

    Attachment 451308

  3. #3
    Join Date
    Jan 2005
    Posts
    15362

    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.

    Attachment 451298

    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
    Join Date
    Aug 2009
    Posts
    1567

    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
    Join Date
    Sep 2018
    Posts
    27

    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
    Join Date
    Aug 2013
    Posts
    4

    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...

    Click image for larger version. 

Name:	Python.jpg 
Views:	1 
Size:	142.4 KB 
ID:	451550

    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
    Join Date
    Sep 2018
    Posts
    27

    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...

    Click image for larger version. 

Name:	Python.jpg 
Views:	1 
Size:	142.4 KB 
ID:	451550

    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 :

  8. #8
    Join Date
    Aug 2013
    Posts
    4

    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:
    Attachment 451566

    And now it works, this is awesome. My pocket and the copied one with added X and Y values:
    Attachment 451568
    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
    Join Date
    Sep 2018
    Posts
    27

    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
    Join Date
    Aug 2013
    Posts
    4

    Re: position changes in G-code

    I attach the python script file
    Attached Files Attached Files

Similar Threads

  1. Check Position M6 Tool Change Code
    By Need TECH Help! in forum Dynomotion/Kflop/Kanalog
    Replies: 5
    Last Post: 04-23-2020, 02:51 AM
  2. Biesse Parking Position Code
    By oferyaar in forum WoodWorking Topics
    Replies: 1
    Last Post: 04-16-2019, 09:25 AM
  3. How to transform a G code into a XYZ position?
    By Gmustang in forum CNC (Mill / Lathe) Control Software (NC)
    Replies: 5
    Last Post: 02-24-2015, 08:33 AM
  4. Code moving to z position before xy
    By richiegore in forum MadCAM
    Replies: 3
    Last Post: 12-16-2010, 05:07 PM
  5. DYNAPATH 20, WHEN E-CODE IS ENTERED, POSITION DISPLAY DOES NOT UPDATE.
    By WEBBERS_14 in forum Uncategorised MetalWorking Machines
    Replies: 0
    Last Post: 08-28-2008, 04:09 PM

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
  •