示例#1
0
def to_gcode(svgfile, gcodefile):
    gcode_compiler = Compiler(DrawbotInterface,
                              movement_speed=1000,
                              cutting_speed=300,
                              pass_depth=0)
    curves = parse_file(svgfile)  # Parse an svg file into geometric curves
    gcode_compiler.append_curves(curves)
    gcode_compiler.compile_to_file(gcodefile, passes=1)
示例#2
0
def generate_gcode(image,
                   movement_speed=1000,
                   cutting_speed=300,
                   pass_depth=0):  # Дифолті налаштування
    gcode_compiler = Compiler(CustomInterface,
                              movement_speed=movement_speed,
                              cutting_speed=cutting_speed,
                              pass_depth=pass_depth)
    image_path = Path(image).resolve()
    curves = parse_file(image_path)
    gcode_compiler.append_curves(curves)
    gcode_compiler.compile_to_file('test.gco')
示例#3
0
def convertSvgToGcode(svg_path, gcode_path):
    try:
        gcode_compiler = Compiler(interfaces.Gcode,
                                  movement_speed=1000,
                                  cutting_speed=300,
                                  pass_depth=0,
                                  unit='mm')
        curves = parse_file(svg_path, transform_origin=False)
        gcode_compiler.append_curves(curves)
        gcode_compiler.compile_to_file(gcode_path)
    except:
        traceback.print_exc()
        return False

    return True
    def effect(self):
        """Takes the SVG from Inkscape, generates gcode, returns the SVG after adding debug lines."""

        root = self.document.getroot()

        # Change svg_to_gcode's approximation tolerance
        TOLERANCES["approximation"] = float(
            self.options.approximation_tolerance.replace(',', '.'))

        # Construct output path
        output_path = os.path.join(self.options.directory,
                                   self.options.filename)
        if self.options.filename_suffix:
            try:
                filename, extension = output_path.split('.')
            except:
                self.msg("Error in output directory!")
                exit(1)

            n = 1
            while os.path.isfile(output_path):
                output_path = filename + str(n) + '.' + extension
                n += 1

        # Load header and footer files
        header = []
        if os.path.isfile(self.options.header_path):
            with open(self.options.header_path, 'r') as header_file:
                header = header_file.read().splitlines()
        elif self.options.header_path != os.getcwd(
        ):  # The Inkscape file selector defaults to the working directory
            self.debug(
                f"Header file does not exist at {self.options.header_path}")

        footer = []
        if os.path.isfile(self.options.footer_path):
            with open(self.options.footer_path, 'r') as footer_file:
                footer = footer_file.read().splitlines()
        elif self.options.footer_path != os.getcwd():
            self.debug(
                f"Footer file does not exist at {self.options.footer_path}")

        # Customize header/footer
        custom_interface = generate_custom_interface(
            self.options.tool_off_command, self.options.tool_power_command)
        interface_instance = custom_interface()

        if self.options.do_laser_off_start:
            header.append(interface_instance.laser_off())
        if self.options.do_laser_off_end:
            footer.append(interface_instance.laser_off())

        header.append(
            interface_instance.set_movement_speed(self.options.travel_speed))
        if self.options.do_z_axis_start:
            header.append(
                interface_instance.linear_move(z=self.options.z_axis_start))
        if self.options.move_to_origin_end:
            footer.append(interface_instance.linear_move(x=0, y=0))

        # Generate gcode
        gcode_compiler = Compiler(custom_interface,
                                  self.options.travel_speed,
                                  self.options.cutting_speed,
                                  self.options.pass_depth,
                                  dwell_time=self.options.dwell_time,
                                  custom_header=header,
                                  custom_footer=footer,
                                  unit=self.options.unit)

        transformation = Transformation()

        transformation.add_translation(self.options.horizontal_offset,
                                       self.options.vertical_offset)
        transformation.add_scale(self.options.scaling_factor)

        if self.options.machine_origin == "center":
            transformation.add_translation(-self.options.bed_width / 2,
                                           self.options.bed_height / 2)
        elif self.options.machine_origin == "top-left":
            transformation.add_translation(0, self.options.bed_height)

        curves = parse_root(root,
                            transform_origin=not self.options.invert_y_axis,
                            root_transformation=transformation,
                            canvas_height=self.options.bed_height)

        gcode_compiler.append_curves(curves)
        gcode_compiler.compile_to_file(output_path, passes=self.options.passes)

        # Draw debug lines
        self.clear_debug()
        if self.options.draw_debug:
            self.draw_debug_traces(curves)
            self.draw_unit_reference()
            self.select_non_debug_layer()

        return self.document
示例#5
0
    def effect(self):
        """Takes the SVG from Inkscape, generates gcode, returns the SVG after adding debug lines."""

        root = self.document.getroot()

        approximation_tolerance = float(
            self.options.approximation_tolerance.replace(',', '.'))

        output_path = os.path.join(self.options.directory,
                                   self.options.filename)
        if self.options.filename_suffix:
            filename, extension = output_path.split('.')

            n = 1
            while os.path.isfile(output_path):
                output_path = filename + str(n) + '.' + extension
                n += 1

        header = None
        if self.options.header_path:
            with open(self.options.header_path, 'r') as header_file:
                header = header_file.readlines()

        footer = None
        if self.options.footer_path:
            with open(self.options.footer_path, 'r') as footer_file:
                footer = footer_file.readlines()

        # Generate gcode
        self.clear_debug()

        TOLERANCES["approximation"] = approximation_tolerance
        custom_interface = generate_custom_interface(
            self.options.laser_off_command, self.options.laser_power_command,
            self.options.laser_power_range)

        gcode_compiler = Compiler(custom_interface,
                                  self.options.travel_speed,
                                  self.options.cutting_speed,
                                  self.options.pass_depth,
                                  dwell_time=self.options.dwell_time,
                                  custom_header=header,
                                  custom_footer=footer,
                                  unit=self.options.unit)

        transformation = Transformation()

        transformation.add_translation(self.options.horizontal_offset,
                                       self.options.vertical_offset)
        transformation.add_scale(self.options.scaling_factor)

        if self.options.machine_origin == "center":
            transformation.add_translation(-self.options.bed_width / 2,
                                           self.options.bed_height / 2)

        transform_origin = True
        if self.options.machine_origin == "top-left":
            transform_origin = False

        curves = parse_root(root,
                            transform_origin=transform_origin,
                            root_transformation=transformation)

        gcode_compiler.append_curves(curves)
        gcode_compiler.compile_to_file(output_path, passes=self.options.passes)

        # Generate debug lines
        if self.options.draw_debug:
            self.draw_debug_traces(curves)
            self.draw_unit_reference()
            self.select_non_debug_layer()

        return self.document
示例#6
0
    def effect(self):
        """Takes the SVG from Inkscape, generates gcode, returns the SVG after adding debug lines."""

        root = self.document.getroot()

        approximation_tolerance = float(
            self.options.approximation_tolerance.replace(',', '.'))

        output_path = os.path.join(self.options.directory,
                                   self.options.filename)
        if self.options.filename_suffix:
            filename, extension = output_path.split('.')

            n = 1
            while os.path.isfile(output_path):
                output_path = filename + str(n) + '.' + extension
                n += 1

        header = None
        if os.path.isfile(self.options.header_path):
            logger.debug(F"going to read{self.options.header_path}")
            with open(self.options.header_path, 'r') as header_file:
                header = header_file.read().splitlines()
                logger.debug(F"This is my header: >>>{header}<<<")
        elif self.options.header_path != os.getcwd():
            self.debug(
                f"Header file does not exist at {self.options.header_path}")

        if self.options.set_z_axis_start_pos:
            unit = "G21"
            if self.options.unit == "in":
                unit = "G20"
            temp = F"{unit};\nG1 Z{self.options.z_axis_start};"
            if header is None:
                header = [temp]
            else:
                header.append(temp)

        footer = None
        if os.path.isfile(self.options.footer_path):
            with open(self.options.footer_path, 'r') as footer_file:
                footer = footer_file.read().splitlines()
        elif self.options.footer_path != os.getcwd():
            self.debug(
                f"Footer file does not exist at {self.options.footer_path}")

        if self.options.move_to_zero_at_end:
            temp = F"M5;\nG1 F{self.options.travel_speed} X0.0 Y0.0 Z0.0;"
            if footer is None:
                footer = [temp]
            else:
                footer.append(temp)

        # Generate gcode
        self.clear_debug()

        TOLERANCES["approximation"] = approximation_tolerance
        custom_interface = generate_custom_interface(
            self.options.laser_off_command, self.options.laser_power_command,
            self.options.laser_power_range)

        gcode_compiler = Compiler(custom_interface,
                                  self.options.travel_speed,
                                  self.options.cutting_speed,
                                  self.options.pass_depth,
                                  dwell_time=self.options.dwell_time,
                                  custom_header=header,
                                  custom_footer=footer,
                                  unit=self.options.unit)

        transformation = Transformation()

        transformation.add_translation(self.options.horizontal_offset,
                                       self.options.vertical_offset)
        transformation.add_scale(self.options.scaling_factor)

        if self.options.machine_origin == "center":
            transformation.add_translation(-self.options.bed_width / 2,
                                           self.options.bed_height / 2)

        curves = parse_root(root,
                            transform_origin=not self.options.invert_y_axis,
                            root_transformation=transformation,
                            canvas_height=self.options.bed_height)

        gcode_compiler.append_curves(curves)
        gcode_compiler.compile_to_file(output_path, passes=self.options.passes)

        # Generate debug lines
        if self.options.draw_debug:
            self.draw_debug_traces(curves)
            self.draw_unit_reference()
            self.select_non_debug_layer()

        return self.document
示例#7
0
from svg_to_gcode.svg_parser import parse_file
from svg_to_gcode.compiler import Compiler, interfaces

# Instantiate a compiler, specifying the interface type and the speed at which the tool should move. pass_depth controls
# how far down the tool moves after every pass. Set it to 0 if your machine does not support Z axis movement.
gcode_compiler = Compiler(interfaces.Gcode, movement_speed=1000, cutting_speed=0, pass_depth=0)

curves = parse_file("SpiralSVG.svg") # Parse an svg file into geometric curves

gcode_compiler.append_curves(curves) 
gcode_compiler.compile_to_file("SpiralSVG.gcode", passes=1)