46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
from svg_to_gcode.svg_parser import parse_string
|
|
from svg_to_gcode.compiler import Compiler, interfaces
|
|
#pip install svg-to-gcode
|
|
|
|
|
|
|
|
class CustomInterface(interfaces.Gcode):
|
|
def __init__(self):
|
|
super().__init__()
|
|
#self.fan_speed = 1
|
|
|
|
# Override the laser_off method such that it gets the pen up
|
|
def laser_off(self):
|
|
return "G0 Z5.0;\n"
|
|
|
|
# Override the set_laser_power method
|
|
def set_laser_power(self, power):
|
|
if power < 0 or power > 1:
|
|
raise ValueError(f"{power} is out of bounds. Laser power must be given between 0 and 1. "
|
|
f"The interface will scale it correctly.")
|
|
|
|
return "G0 Z0.0;\n"
|
|
|
|
# def home_axes(self):
|
|
# return "$H;"
|
|
def home_cycle():
|
|
return "$H; \n G92 X0 Y750"
|
|
|
|
|
|
def convertToGcode(targetData, output):
|
|
|
|
#creating a compiler with the custom inteface class
|
|
#also giving a custom header with the function home_cycle()
|
|
gcode_compiler = Compiler(CustomInterface, movement_speed=1000, cutting_speed=300, pass_depth=5,custom_header = [CustomInterface.home_cycle()])
|
|
|
|
|
|
curves = parse_string(targetData) # Parse an svg file into geometric curves
|
|
gcode_compiler.append_curves(curves)
|
|
|
|
return gcode_compiler.compile(passes=1)
|
|
|
|
|
|
|
|
|
|
|