replace Mxx code
05 Apr 2013 19:26 #32306
by FabioP
replace Mxx code was created by FabioP
Hi all,
I have a script code under "Filter" that works fine,
#!/usr/bin/env python
# gcode2ngc.py
import sys
# First line
print "%"
f = file(sys.argv[1])
for line in f:
# Change extruder axis name
line = line.replace(" E", " A")
# S -> P
line = line.replace(" S", " P")
# Comment T0 code
line = line.replace("T0", ";T0")
# Comment G28 code
line = line.replace("G28", ";G28")
# Comment M82 code
line = line.replace("M82", ";M82")
print line.strip()
# Last line
print "%"
but if I try to replace M101 to M3 or M106 to A50 don't work, any suggestions?
I have a script code under "Filter" that works fine,
#!/usr/bin/env python
# gcode2ngc.py
import sys
# First line
print "%"
f = file(sys.argv[1])
for line in f:
# Change extruder axis name
line = line.replace(" E", " A")
# S -> P
line = line.replace(" S", " P")
# Comment T0 code
line = line.replace("T0", ";T0")
# Comment G28 code
line = line.replace("G28", ";G28")
# Comment M82 code
line = line.replace("M82", ";M82")
print line.strip()
# Last line
print "%"
but if I try to replace M101 to M3 or M106 to A50 don't work, any suggestions?
Please Log in or Create an account to join the conversation.
05 Apr 2013 20:17 - 05 Apr 2013 20:27 #32307
by BigJohnT
Replied by BigJohnT on topic replace Mxx code
What is the python line of code you tried for M101?
What does the original line look like?
Edit: line = line.replace('M101','M1') will fail because it is not the same number of characters.
John
What does the original line look like?
Edit: line = line.replace('M101','M1') will fail because it is not the same number of characters.
John
Last edit: 05 Apr 2013 20:27 by BigJohnT.
Please Log in or Create an account to join the conversation.
05 Apr 2013 21:07 - 05 Apr 2013 21:09 #32308
by ArcEye
Replied by ArcEye on topic replace Mxx code
You could just use sed
You don't have to use completely obfuscated patterns, just simple global substitution ones
$ sed -e 's/M101/M3/'g -e 's/M105/A50/'g -e 's/E/A/'g -e 's/S/P/'g -e 's/T0/;T0/'g -e 's/G28/;G28/'g -e 's/M82/;M82/'g in.ngc > out.ngc
regards
You don't have to use completely obfuscated patterns, just simple global substitution ones
$ sed -e 's/M101/M3/'g -e 's/M105/A50/'g -e 's/E/A/'g -e 's/S/P/'g -e 's/T0/;T0/'g -e 's/G28/;G28/'g -e 's/M82/;M82/'g in.ngc > out.ngc
regards
Last edit: 05 Apr 2013 21:09 by ArcEye.
Please Log in or Create an account to join the conversation.
05 Apr 2013 22:42 #32311
by FabioP
Replied by FabioP on topic replace Mxx code
John, yes, original line was like this:
# Comment M101 code
line = line.replace("M101", "M3") and now understand because it is failed ! thanks.
ArcEye, I don't know sed,where I should put this code,thanks
Fabio
# Comment M101 code
line = line.replace("M101", "M3") and now understand because it is failed ! thanks.
ArcEye, I don't know sed,where I should put this code,thanks
Fabio
Please Log in or Create an account to join the conversation.
05 Apr 2013 23:23 - 07 Apr 2013 17:08 #32312
by ArcEye
It is a command-line program, run from a terminal. See man sed
If you wanted to run it in a script
will convert all the .nc files in the current directory, making a backup of the original with extension .bak
and outputting a file with .ngc extension
You could convert into a filter, but not sure if there is a need, you only have to run it once and it is done.
regards
Replied by ArcEye on topic replace Mxx code
ArcEye, I don't know sed,where I should put this code,thanks
It is a command-line program, run from a terminal. See man sed
If you wanted to run it in a script
# !/bin/bash
for j in *.nc
{
sed -i.bak -e 's/M101/M3/'g -e 's/M105/A50/'g -e 's/E/A/'g -e 's/S/P/'g -e 's/T0/;T0/'g -e 's/G28/;G28/'g -e 's/M82/;M82/'g $j
name='basename $j .nc'
mv $j $name.ngc
}
exit(0)
will convert all the .nc files in the current directory, making a backup of the original with extension .bak
and outputting a file with .ngc extension
You could convert into a filter, but not sure if there is a need, you only have to run it once and it is done.
regards
Last edit: 07 Apr 2013 17:08 by ArcEye. Reason: substitute j for i, to prevent any clash with sed -i switch
Please Log in or Create an account to join the conversation.
Time to create page: 0.190 seconds