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.
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:
...write the Pocket/Program in Incremental G91 XY coordinates... then minor Editing to shift with G90 to move pocket anywhere you need possibility.
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 !
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...
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
I found the Python console and it returned this error message:
I searched the web and could solve this by adding a "space" in front all three "return... lines, then it looked like this: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
And now it works, this is awesome. My pocket and the copied one with added X and Y values:
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
Oops, it lost identation when I copy/paste the code I guess, sorry for that.
Im glad you have your solution !
I attach the python script file