Exemplo n.º 1
0
def main():
    """command line entry point"""
    parser = argparse.ArgumentParser(description='Modify GCode program to account for stretch and improve hole size')

    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('--cross_limit_distance_over_edge_width', type=float, default=5.0,
                        help='Distance after and before a point where moves are considered to determine the local '
                             'normal. Defaults to %(default)s. Set too low or too high, it might cause points no to be '
                             'moved in the right direction.')
    parser.add_argument('--stretch_from_distance_over_edge_width', type=float, default=2.0,
                        help='Distance after and before a point where moves are considered to determine the local '
                             'normal. Defaults to %(default)s. Set too low or too high, it might cause points no to be '
                             'moved in the right direction.')

    parser.add_argument('--loop_stretch_over_edge_width', type=float, default=0.11,
                        help='Stretching strength for "loop" (extra shells), defaults to %(default)s')
    parser.add_argument('--edge_inside_stretch_over_edge_width', type=float, default=0.32,
                        help='Stretching strength for "inner perimeter", defaults to %(default)s')
    parser.add_argument('--edge_outside_stretch_over_edge_width', type=float, default=0.1,
                        help='Stretching strength for "outer perimeter", defaults to %(default)s')

    parser.add_argument('--stretch_strength', type=float, default=1.0,
                        help='Stretching stretch factor. This is the first setting you\'ll want to change to '
                             'modify the hole size')

    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())  # pylint: disable=redefined-outer-name

    # First convert to relative extrusion
    GCodeToRelativeExtrusionFilter().filter(gcode)

    # Then perform the stretching
    if is_cura_gcode(gcode):
        CuraStretchFilter(**vars(args)).filter(gcode)
    else:
        Slic3rStretchFilter(**vars(args)).filter(gcode)

    # write back modified gcode
    gcode.write(args.outfile)
Exemplo n.º 2
0
def test_trivial_iteration():
    gcode = GCode(layer1.split("\n"))

    cmp_ite(LineIteratorForwardLegacy(0, gcode.all_layers[0]), xrange(1, 6))

    for start_index in xrange(1, 6):
        cmp_ite(LineIteratorForwardLegacy(start_index, gcode.all_layers[0]),
                xrange(start_index, 6))
Exemplo n.º 3
0
def main():
    """command line entry point"""
    parser = argparse.ArgumentParser(
        description=
        'Modify GCode program to account arcs and replace the G1 with G2/G3')

    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('--inplace',
                        '-i',
                        action='store_true',
                        help='Modify file inplace')

    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())  # pylint: disable=redefined-outer-name

    # First convert to relative extrusion
    # GCodeToRelativeExtrusionFilter().filter(gcode)

    # Then perform the stretching
    GCodeArcOptimizerFilter().filter(gcode)

    # write back modified gcode
    gcode.write(
        open(args.infile.name, 'w')
        if args.inplace is True and args.infile != sys.stdin else args.outfile)
Exemplo n.º 4
0
"""

import math
import re
from itertools import takewhile
from more_itertools import split_when

import gcodeutils.gcoder
from gcodeutils.gcoder import GCode

# Allow whitespace between axis name and coordinate
gcodeutils.gcoder.gcode_exp = re.compile(
    "\([^\(\)]*\)|^\(.*\)$|;.*|[/\*].*\n|([%s])\s*([-+]?[0-9]*\.?[0-9]*)" %
    gcodeutils.gcoder.to_parse)

pattern = GCode(open("diffuse_0001_half.gcode"))


def is_g0(line):
    return line.command == "G00"


def not_g0(line):
    return line.command != "G00"


class Segment:
    def __init__(self, lines):
        self.lines = lines
        self.startpos = self._startpos()
        self.endpos = self._endpos()
Exemplo n.º 5
0
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('-p',
                        type=int,
                        metavar='layer',
                        help='Pause the gcode program at layer <layer>.')

    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)

    iterator = GCodeIterator(gcode)
    if args.p is not None:
        visitor = PauseAtLayer([args.p])
        iterator.accept(visitor)

    # write back modified gcode
    gcode.write(args.outfile)
Exemplo n.º 6
0
def open_gcode_file(filename):
    with open(
            os.path.join(os.path.dirname(os.path.abspath(__file__)),
                         filename)) as gcode:
        return GCode(gcode.readlines())
Exemplo n.º 7
0
#Name: Temp tower
#Info: Update temperature continuously
#Depend: GCode
#Type: postprocess
#Param: start_temp(float:150) Temperature at bottom of calibration object
#Param: end_temp(float:240) Temperature at top of calibration object
#Param: min_z_change(float:3) Minimum Z for changing temperatures
#Param: steps(float:10) Number of steps

# hack for windows platform with a non system wide python so that you can
# just copy gcodeutils into the plugins directory instead of installing it
# no twinkles for you, ultimaker
import sys
sys.path.append('plugins')

from gcodeutils.gcode_tempcal import GCodeStepTempGradient
from gcodeutils.gcoder import GCode

with open(filename, 'r') as gcode_file:  # pylint: disable=undefined-variable
    gcode = GCode(gcode_file)  # pylint: disable=redefined-outer-name,invalid-name

with open(filename, 'w') as gcode_file:  # pylint: disable=undefined-variable
    GCodeStepTempGradient(gcode=gcode,
                          start_temp=start_temp,
                          end_temp=end_temp,
                          min_z_change=min_z_change,
                          steps=steps).write(gcode_file)