action="store", type="string", dest="output_file") parser.add_option("-i", "--image", action="store_true", dest="image", default=False) options, args = parser.parse_args() # Check for required options for required in ("output_file", ): if getattr(options, required, None) is None: print "Missing required option '%s'" % required print USAGE.strip() % argv[0] exit(1) # Check positional arguments if len(args) <> 1: print USAGE.strip() % argv[0] exit(1) # Process the file gcode = loadGCode(args[0]) if (gcode.minx <> 0) or (gcode.miny <> 0): print "Translating file by dx = %0.4f, dy = %0.4f" % (-gcode.minx, -gcode.miny) gcode = gcode.clone(Translate(-gcode.minx, -gcode.miny)) else: print "No translation required." saveGCode(options.output_file, gcode) if options.image: gcode.render(splitext(options.output_file)[0] + ".png")
print "ERROR: Missing output file" print USAGE.strip() % argv[0] exit(1) # Load defaults getSettings(CONTROL, options) # Show current settings print "Selected options:" for k in sorted(CONTROL.keys()): if not (k in ("prefix", "suffix")): print " %-10s: %s" % (k, str(CONTROL[k])) # Get the filename name, ext = splitext(args[0]) if ext == "": ext = ".ngc" filename = name + ext # Generate the gcode print "\nCreating file '%s'" % args[0] gcode = GCode() if options.center: centerCut(gcode) else: areaCut(gcode) # Save the result saveGCode(filename, gcode, prefix = CONTROL['prefix'], suffix = CONTROL['suffix']) print " %s" % str(gcode) # Save the image (if requested) if options.image: filename = name + ".png" gcode.render(filename, showall = True) print "Generated image '%s'" % filename
""" #--- Main program if __name__ == "__main__": # Set up program options parser = OptionParser() parser.add_option("-c", "--cut", action="store", type="float", dest="cut_depth") parser.add_option("-s", "--safe", action="store", type="float", dest="safe_depth") parser.add_option("-o", "--output", action="store", type="string", dest="output_file") options, args = parser.parse_args() # Check for required options for required in ("output_file", ): if getattr(options, required, None) is None: print "Missing required option '%s'" % required print USAGE.strip() % argv[0] exit(1) # Check positional arguments if len(args) <> 1: print USAGE.strip() % argv[0] exit(1) # Set up the source file and collect the depth information source = args[0] if (options.cut_depth is None) and (options.safe_depth is None): print "You haven't asked me to do anything!" exit(1) # Now process the file gcode = loadGCode(source) gcode = gcode.clone(ZLevel(cut = options.cut_depth, safe = options.safe_depth)) saveGCode(options.output_file, gcode)
# Load defaults getSettings(CONTROL, options) # Show current settings print "Selected options:" for k in sorted(CONTROL.keys()): if not (k in ("prefix", "suffix")): print " %-10s: %s" % (k, str(CONTROL[k])) # Get the filename name, ext = splitext(args[0]) if ext == "": ext = ".ngc" filename = name + ext # Generate the gcode print "\nCreating file '%s'" % args[0] gcode = GCode() if options.center: centerCut(gcode) else: areaCut(gcode) # Save the result saveGCode(filename, gcode, prefix=CONTROL['prefix'], suffix=CONTROL['suffix']) print " %s" % str(gcode) # Save the image (if requested) if options.image: filename = name + ".png" gcode.render(filename, showall=True) print "Generated image '%s'" % filename
"--image", action="store_true", dest="image", default=False) options, args = parser.parse_args() # Check positional arguments if len(args) <> 1: print USAGE.strip() % argv[0] exit(1) # Make sure required arguments are present for req in ("output", "angle"): if getattr(options, req) is None: print "ERROR: Missing required argument '%s'" % req print USAGE.strip() % argv[0] exit(1) source = args[0] # Process the file gcode = loadGCode(source) print "Loaded - %s" % str(gcode) gcode = gcode.clone(Rotate(options.angle)) print "Generated - %s" % str(gcode) # Generate an image if required name, ext = splitext(options.output) if options.image: filename = name + ".png" gcode.render(filename) # Generate the output file if ext == "": ext = ".ngc" saveGCode(name + ext, gcode)
parser.add_option("-a", "--angle", action="store", type="float", dest="angle") parser.add_option("-o", "--output", action="store", type="string", dest="output") parser.add_option("-i", "--image", action="store_true", dest="image", default=False) options, args = parser.parse_args() # Check positional arguments if len(args) <> 1: print USAGE.strip() % argv[0] exit(1) # Make sure required arguments are present for req in ("output", "angle"): if getattr(options, req) is None: print "ERROR: Missing required argument '%s'" % req print USAGE.strip() % argv[0] exit(1) source = args[0] # Process the file gcode = loadGCode(source) print "Loaded - %s" % str(gcode) gcode = gcode.clone(Rotate(options.angle)) print "Generated - %s" % str(gcode) # Generate an image if required name, ext = splitext(options.output) if options.image: filename = name + ".png" gcode.render(filename) # Generate the output file if ext == "": ext = ".ngc" saveGCode(name + ext, gcode)