def main(): """command line entry point""" parser = argparse.ArgumentParser( description='Add temperature gradient to gcode program') parser.add_argument( 'start_temp', type=int, help='Initial temperature (best set to the default slicing temperature).' ' For instance, for ABS you may want 240 and 200 for PLA.') parser.add_argument( 'end_temp', type=int, help= 'End temperature for the gcode program. Usually lower than the initial temperature. ' 'Make sure that your material can be still be extruded at this temperature ' 'to avoid clogging your extruder.') parser.add_argument( 'infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='Program filename to be modified. Defaults to standard input.') parser.add_argument( 'outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout, help= 'Modified program with temperature gradient. Defaults to standard output.' ) parser.add_argument( '--min_z_change', '-z', type=float, default=0.1, help='Minimum height above which temperature gradient is created. ' 'If you have a special start sequence playing with temperatures, you may want to raise ' 'this to avoid overlapping of temperature. Defaults to %(default)smm which is compatible ' 'with NopHead ooze free unattended start sequence.') temperature_control = parser.add_argument_group('temperature control') temperature_control.add_argument( '--continuous', '-c', action='store_const', const=GCodeContinuousTempGradient, dest='gcode_grad_class', default=GCodeStepTempGradient, help= 'Switch to a continuous gradient generation where temperature is recomputed ' 'for every layer. You may want this in the case of very precise and fast ' 'hotend. Defaults to discrete temperature gradient divided in X steps.' ) temperature_control.add_argument( '--steps', '-s', default=10, help= 'Number of steps used to create a discrete gradient when using the default ' 'gradient generation model. Defaults to %(default)s steps. This setting is ' 'not used when using the continuous gradient generation model.') parser.add_argument( '--verbose', '-v', action='count', default=1, help= 'Verbose mode. It notably outputs the mapping between temperature and height if you have ' 'troubles figuring it out.') parser.add_argument('--quiet', '-q', action='count', default=0, help='Quiet mode') args = parser.parse_args() # count verbose and quiet flags to determine logging level args.verbose -= args.quiet if args.verbose > 1: logging.root.setLevel(logging.DEBUG) elif args.verbose > 0: logging.root.setLevel(logging.INFO) logging.basicConfig(format="%(levelname)s:%(message)s") # read original GCode gcode = GCode(args.infile.readlines()) # Alter and write back modified GCode temp_gradient = args.gcode_grad_class(gcode=gcode, **vars(args)) temp_gradient.write(args.outfile)
def measurements(g): gcode = GCode(g) gcode.measure() return (gcode.width, gcode.depth, gcode.height, gcode.xmin, gcode.xmax, gcode.ymin, gcode.ymax, gcode.zmin, gcode.zmax)
def totalelength(g): gcode = GCode(g) return gcode.filament_length()
def main(): """command line entry point""" parser = argparse.ArgumentParser(description='Modify gcode program') parser.add_argument( '-x', type=float, metavar='amount', help='Move all gcode program by <amount> units in the X axis.') parser.add_argument( '-y', type=float, metavar='amount', help='Move all gcode program by <amount> units in the Y axis.') parser.add_argument('-e', action='count', default=0, help='Convert all extrusion to relative') parser.add_argument( 'infile', nargs='?', type=argparse.FileType('r'), default=sys.stdin, help='Program filename to be modified. Defaults to standard input.') parser.add_argument('outfile', nargs='?', type=argparse.FileType('w'), default=sys.stdout, help='Modified program. Defaults to standard output.') parser.add_argument('--verbose', '-v', action='count', default=1, help='Verbose mode') parser.add_argument('--quiet', '-q', action='count', default=0, help='Quiet mode') args = parser.parse_args() # count verbose and quiet flags to determine logging level args.verbose -= args.quiet if args.verbose > 1: logging.root.setLevel(logging.DEBUG) elif args.verbose > 0: logging.root.setLevel(logging.INFO) logging.basicConfig(format="%(levelname)s:%(message)s") # read original GCode gcode = GCode(args.infile.readlines()) if args.x is not None or args.y is not None: GCodeXYTranslateFilter(**vars(args)).filter(gcode) if args.e: GCodeToRelativeExtrusionFilter().filter(gcode) # write back modified gcode gcode.write(args.outfile)