#! /usr/bin/env python

import sys

def main(argv):
	
  openfile = open(argv[0], 'r')
  file_in = openfile.readlines()
  openfile.close()
  
  skip_print = -1
  file_out = []
  for line in file_in:
       if line.find('rfl') != -1:
         print line.rstrip('\n')
         skip_print *= -1
       else:
         if skip_print != -1:
           print line.rstrip('\n')
      
if __name__ == "__main__":
   main(sys.argv[1:])



# If you are working with many subroutines, there likely would happen some problems with run from line
# for safe workflow this filter can be used, you decide which lines in your code will be used for machining.

# ini  [FILTER]
# PROGRAM_EXTENSION = .py Python Script

# py = python
# rfl = /home/path/to/folder/rfl.py

# sudo chmod 755 /home/path/to/folder/rfl.py and set executable.

# Make a copy of your ngc file, attach ending .rfl to your ngc file to make it recognized by the filter.
#   eg  AirguideX.ngc.rfl   It is tested with AXIS.
# Always 2 lines must have at least the comment (rfl). For better understanding,
# (rfl_s), (rfl_e) etc is accepted. So this lines and the lines between are in the filtered file for machining now.
# The last section until EOF, only need the start mark. If you don't go to EOF, last line with M30 needs (rfl) also.
