Creating a Script
26 Mar 2013 17:43 #31902
by BigJohnT
Todd,
Does the filter script work for you when you use it stand alone from the terminal?
John
Replied by BigJohnT on topic Creating a Script
I think I would still like to learn how to modify John's script to work with as an axis filter.
Todd,
Does the filter script work for you when you use it stand alone from the terminal?
John
Please Log in or Create an account to join the conversation.
26 Mar 2013 17:58 - 26 Mar 2013 18:06 #31904
by BigJohnT
Replied by BigJohnT on topic Creating a Script
Todd,
Here are the steps I took to use the stand alone script as a filter in Axis.
In the [FILTER] section I added the following and I just picked nc as a file extension out of the blue. I put the python program todd.py in the directory pointed to. You could also put it in usr/bin I think and be able to skip the full path...
I changed the code to print the output instead of creating a file after a bit of testing.
Now if I open a file with a .nc extension it will get put through the filter and then into Axis. It does not change the original file! If you want to save the file use Save gcode as.
Edit: the script does depend on there being a space between each word like G1 G3 X1 Y0.625 Z-0.5
I guess a more clever approach would be to find the Z or z and read in up to the next letter or end of line then append the W part.
John
Here are the steps I took to use the stand alone script as a filter in Axis.
In the [FILTER] section I added the following and I just picked nc as a file extension out of the blue. I put the python program todd.py in the directory pointed to. You could also put it in usr/bin I think and be able to skip the full path...
[FILTER]
PROGRAM_EXTENSION = .nc Convert to W Axis
nc = /home/john/linuxcnc/todd/todd.py
I changed the code to print the output instead of creating a file after a bit of testing.
#! /usr/bin/env python
import sys
def main(argv):
openfile = open(argv[0], 'r')
file_in = openfile.readlines()
openfile.close()
file_out = []
for line in file_in:
# print line
if line.find('Z') != -1:
words = line.rstrip('\n')
words = words.split(' ')
newword = ''
for i in words:
if i[0] == 'Z':
newword = 'W'+ i[1:]
if len(newword) > 0:
words.append(newword)
newline = ' '.join(words)
file_out.append(newline)
else:
file_out.append(line)
for item in file_out:
print "%s" % item
if __name__ == "__main__":
main(sys.argv[1:])
Now if I open a file with a .nc extension it will get put through the filter and then into Axis. It does not change the original file! If you want to save the file use Save gcode as.
Edit: the script does depend on there being a space between each word like G1 G3 X1 Y0.625 Z-0.5
I guess a more clever approach would be to find the Z or z and read in up to the next letter or end of line then append the W part.
John
Last edit: 26 Mar 2013 18:06 by BigJohnT.
Please Log in or Create an account to join the conversation.
26 Mar 2013 18:04 - 26 Mar 2013 18:09 #31905
by BigJohnT
Replied by BigJohnT on topic Creating a Script
I took this file I called todd2.nc
And ran it through the filter and got this:
John
G1 X7.286672 Y10.920909 Z-0.165422
G1 X7.290075 Y10.882176 Z-0.162863
G1 X7.289496 Y0.985702 Z-0.161858
G1 X7.286561 Y0.942836 Z-0.161923
G1 X7.280504 Y0.912766 Z-0.166510
G1 X7.256354 Y0.833603 Z-0.159223
G00 Z0.25
G00 X7.006710 Y0.939417 Z0.25
G00 Z0.0
G1 X7.006710 Y0.939417 Z-0.079312
G1 X6.995858 Y0.916412 Z-0.086247
G1 X6.980558 Y0.899274 Z-0.080125
G1 X6.937673 Y0.867952 Z-0.085329
G1 X6.918087 Y0.863142 Z-0.087211
G1 X6.889543 Y0.859730 Z-0.086135
M2
And ran it through the filter and got this:
G1 X7.286672 Y10.920909 Z-0.165422 W-0.165422
G1 X7.290075 Y10.882176 Z-0.162863 W-0.162863
G1 X7.289496 Y0.985702 Z-0.161858 W-0.161858
G1 X7.286561 Y0.942836 Z-0.161923 W-0.161923
G1 X7.280504 Y0.912766 Z-0.166510 W-0.166510
G1 X7.256354 Y0.833603 Z-0.159223 W-0.159223
G00 Z0.25 W0.25
G00 X7.006710 Y0.939417 Z0.25 W0.25
G00 Z0.0 W0.0
G1 X7.006710 Y0.939417 Z-0.079312 W-0.079312
G1 X6.995858 Y0.916412 Z-0.086247 W-0.086247
G1 X6.980558 Y0.899274 Z-0.080125 W-0.080125
G1 X6.937673 Y0.867952 Z-0.085329 W-0.085329
G1 X6.918087 Y0.863142 Z-0.087211 W-0.087211
G1 X6.889543 Y0.859730 Z-0.086135 W-0.086135
M2
John
Last edit: 26 Mar 2013 18:09 by BigJohnT.
The following user(s) said Thank You: Todd Zuercher
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
26 Mar 2013 20:17 #31913
by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Please Log in or Create an account to join the conversation.
26 Mar 2013 20:27 #31916
by BigJohnT
Replied by BigJohnT on topic Creating a Script
What is your INI line for z-zw.py?
You can put the file anywhere you like if you use the full path to the file in your INI.
I didn't test it in /usr/bin but I assume you need to copy it using sudo and make it executable.
John
You can put the file anywhere you like if you use the full path to the file in your INI.
I didn't test it in /usr/bin but I assume you need to copy it using sudo and make it executable.
John
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
26 Mar 2013 21:37 #31924
by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
I tried it both ways with the full path in /home/enroute3/linuxcnc/nc-files/ and with it saved to /usr/bin (using sudo) and the file(s) were made exicutable. All gave the same results.
If I had the path wrong in the ini file it gave a different error, saying that it could not find the script. In this case /bad path name/z-zw.py.
If I had the path wrong in the ini file it gave a different error, saying that it could not find the script. In this case /bad path name/z-zw.py.
Please Log in or Create an account to join the conversation.
26 Mar 2013 22:50 #31928
by BigJohnT
Replied by BigJohnT on topic Creating a Script
I think I understand what the problem is. Put z-zw.py in the same directory as the file your converting and have your ini file point to that directory.
John
John
Please Log in or Create an account to join the conversation.
- Todd Zuercher
- Topic Author
- Offline
- Platinum Member
Less
More
- Posts: 5007
- Thank you received: 1441
26 Mar 2013 23:19 #31931
by Todd Zuercher
Replied by Todd Zuercher on topic Creating a Script
Please Log in or Create an account to join the conversation.
27 Mar 2013 06:34 #31949
by BigJohnT
Replied by BigJohnT on topic Creating a Script
The script with print "%s" % item should not be run from the command line.
I see you must have ran the other file a few times as I see the converted files.
Are you using a stock 10.04 LiveCD install? It seems to be choking on the location of python in the first line of the script.
John
I see you must have ran the other file a few times as I see the converted files.
Are you using a stock 10.04 LiveCD install? It seems to be choking on the location of python in the first line of the script.
John
Please Log in or Create an account to join the conversation.
27 Mar 2013 06:52 #31950
by arvidb
Maybe because I forgot to quote the file name parameter in the script. Is there by any chance a space in your network file path?
Fire up gedit:and add quotes to $1, like this:
Does that work?
Replied by arvidb on topic Creating a Script
Ok, this sed script works but...
It will load and convert files saved on the hard drive, but when I try to load a file that was saved on our network I get file not found errors. But files opened from the network that don't go through the script still open fine. Why?
Maybe because I forgot to quote the file name parameter in the script. Is there by any chance a space in your network file path?
Fire up gedit:
$ sudo gedit /usr/bin/w_add.sh
sed 's|Z\([-.0-9]*\)|Z\1 W\1|g' "$1"
Does that work?
Please Log in or Create an account to join the conversation.
Time to create page: 0.135 seconds