added cli
This commit is contained in:
1 parent
b302aa17df
commit
9d3fbb492c
7 files changed
+652954
-51
No files matched your search
@@ -1,6 +1,5 @@
|
||||
"""G-code emitted at the start of processing the SVG file"""
|
||||
preamble = "(preamble)"
|
||||
#preamble = "G1 X0, Y0, Z100"
|
||||
preamble = "G90"
|
||||
|
||||
|
||||
"""G-code emitted at the end of processing the SVG file"""
|
||||
@@ -15,21 +14,30 @@ shape_postamble = "(shape postamble)"
|
||||
#shape_postamble = "Z100)"
|
||||
|
||||
"""Print bed width in mm"""
|
||||
bed_max_x = 200000
|
||||
bed_max_x = 200
|
||||
|
||||
"""Print bed height in mm"""
|
||||
bed_max_y = 200000
|
||||
bed_max_y = 280
|
||||
|
||||
"""
|
||||
Used to control the smoothness/sharpness of the curves.
|
||||
Smaller the value greater the sharpness. Make sure the
|
||||
value is greater than 0.1
|
||||
"""
|
||||
smoothness = 10
|
||||
smoothness = 0.0101
|
||||
smoothness = 40
|
||||
|
||||
|
||||
""" height that the z axis will use to travel between strokes """
|
||||
zTravel = 4
|
||||
|
||||
zTravel = 100
|
||||
|
||||
""" height that the z axis will use to draw """
|
||||
zDraw = 0
|
||||
|
||||
""" feed rate """
|
||||
feed_rate = 80000
|
||||
|
||||
""" decimal precision of gcode"""
|
||||
precision = 2
|
||||
|
||||
auto_scale = False
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
from svg2gcode import generate_gcode
|
||||
import sys
|
||||
# from config import *
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("usage: python convert.py source.svg destination.gcode")
|
||||
sys.exit()
|
||||
|
||||
source = sys.argv[1]
|
||||
target = sys.argv[2]
|
||||
|
||||
|
||||
|
||||
print("converting!")
|
||||
|
||||
print(source, target)
|
||||
|
||||
with open(target, 'w+') as output_file:
|
||||
g = generate_gcode(source)
|
||||
for i in g:
|
||||
output_file.write(i + "\n")
|
||||
|
||||
print("done!")
|
||||
+12
-1
@@ -22,6 +22,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
import simplepath
|
||||
from math import *
|
||||
|
||||
|
||||
def matprod(mlist):
|
||||
prod = mlist[0]
|
||||
for m in mlist[1:]:
|
||||
@@ -31,16 +32,23 @@ def matprod(mlist):
|
||||
a11 = prod[1][0] * m[0][1] + prod[1][1] * m[1][1]
|
||||
prod = [[a00, a01], [a10, a11]]
|
||||
return prod
|
||||
|
||||
|
||||
def rotmat(teta):
|
||||
return [[cos(teta), -sin(teta)], [sin(teta), cos(teta)]]
|
||||
|
||||
|
||||
def applymat(mat, pt):
|
||||
x = mat[0][0] * pt[0] + mat[0][1] * pt[1]
|
||||
y = mat[1][0] * pt[0] + mat[1][1] * pt[1]
|
||||
pt[0] = x
|
||||
pt[1] = y
|
||||
|
||||
|
||||
def norm(pt):
|
||||
return sqrt(pt[0] * pt[0] + pt[1] * pt[1])
|
||||
|
||||
|
||||
def ArcToPath(p1, params):
|
||||
A = p1[:]
|
||||
rx, ry, teta, longflag, sweepflag, x2, y2 = params[:]
|
||||
@@ -97,6 +105,7 @@ def ArcToPath(p1,params):
|
||||
applymat(mat, pts[2])
|
||||
return (p)
|
||||
|
||||
|
||||
def CubicSuperPath(simplepath):
|
||||
csp = []
|
||||
subpath = -1
|
||||
@@ -150,6 +159,7 @@ def CubicSuperPath(simplepath):
|
||||
csp[subpath].append([lastctrl[:], last[:], last[:]])
|
||||
return csp
|
||||
|
||||
|
||||
def unCubicSuperPath(csp):
|
||||
a = []
|
||||
for subpath in csp:
|
||||
@@ -159,11 +169,12 @@ def unCubicSuperPath(csp):
|
||||
a.append(['C', subpath[i - 1][2][:] + subpath[i][0][:] + subpath[i][1][:]])
|
||||
return a
|
||||
|
||||
|
||||
def parsePath(d):
|
||||
return CubicSuperPath(simplepath.parsePath(d))
|
||||
|
||||
|
||||
def formatPath(p):
|
||||
return simplepath.formatPath(unCubicSuperPath(p))
|
||||
|
||||
|
||||
# vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 fileencoding=utf-8 textwidth=99
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Generator: Adobe Illustrator 22.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
||||
<svg version="1.0" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
||||
viewBox="0 0 612 792" enable-background="new 0 0 612 792" xml:space="preserve">
|
||||
<rect x="56.8" y="123.5" fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" width="150" height="128.1"/>
|
||||
<path fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" d="M401,237.5H290.8c-6.6,0-12-5.4-12-12v-83.9c0-6.6,5.4-12,12-12
|
||||
H401c6.6,0,12,5.4,12,12v83.9C413,232.1,407.6,237.5,401,237.5z"/>
|
||||
<ellipse fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" cx="146.3" cy="373.9" rx="71.9" ry="49.6"/>
|
||||
<circle fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" cx="325.7" cy="380.1" r="55.7"/>
|
||||
<polygon fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" points="193.7,655.9 103.1,658.4 55.8,581.2 98.9,501.6
|
||||
189.5,499.1 236.8,576.3 "/>
|
||||
<polygon fill="#FFFFFF" stroke="#000000" stroke-miterlimit="10" points="448.1,649.8 388.3,619.5 329.5,651.6 339.8,585.4
|
||||
291.1,539.4 357.3,528.8 386,468.2 416.6,527.9 483,536.5 435.7,584 "/>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
@@ -0,0 +1,8 @@
|
||||
|
||||
(Created with svg2gcode_grbl)
|
||||
(https://github.com/arcadeperfect/svg2gcode_grbl)
|
||||
|
||||
|
||||
(forked from svg2gcode by visphat)
|
||||
(https://github.com/vishpat/svg2gcode)
|
||||
|
||||
+84
-43
@@ -7,7 +7,7 @@ from shapes import point_generator
|
||||
from config import *
|
||||
import re
|
||||
|
||||
path = "./svg/example.svg"
|
||||
# path = "./svg/example.svg"
|
||||
|
||||
# path = "./svg/big_example.svg"
|
||||
# path = "./svg/medium_example.svg"
|
||||
@@ -15,9 +15,11 @@ path = "./svg/example.svg"
|
||||
# path = "./svg/grid.svg"
|
||||
# path = "./svg/Lorenz_attractor.svg"
|
||||
# path = "./svg/text.svg"
|
||||
# path = "./svg/A.svg"
|
||||
path = "./example.svg"
|
||||
|
||||
|
||||
output = "./gcode/output.gcode"
|
||||
output = "./gcode/output2.gcode"
|
||||
output = "temp.gcode"
|
||||
|
||||
debug = False
|
||||
|
||||
@@ -29,24 +31,21 @@ debug = False
|
||||
# todo make interface
|
||||
|
||||
|
||||
def generate_gcode(path):
|
||||
def generate_gcode(path, autoScale = True):
|
||||
svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path'])
|
||||
precision = 1
|
||||
|
||||
|
||||
with open("header.txt") as headerFile:
|
||||
header = headerFile.read()
|
||||
# preamble = ""
|
||||
# with open("header.txt") as headerFile:
|
||||
# for cnt, line in enumerate(headerFile):
|
||||
# preamble += f"({line})\n"
|
||||
|
||||
|
||||
commands = []
|
||||
|
||||
tree = ET.parse(path)
|
||||
# tree = ET.parse(sys.stdin)
|
||||
root = tree.getroot()
|
||||
|
||||
# print("\n printing root.iter")
|
||||
# for i in root.iter():
|
||||
# print(i.tag)
|
||||
#
|
||||
# print("\n printing root with tag and attrib")
|
||||
# for i in root:
|
||||
# print(i.tag, i.attrib)
|
||||
|
||||
width = root.get('width')
|
||||
height = root.get('height')
|
||||
|
||||
@@ -59,34 +58,40 @@ def generate_gcode(path):
|
||||
print("Unable to get width and height for the svg")
|
||||
sys.exit(1)
|
||||
|
||||
width = re.sub("[^0-9]", "", width)
|
||||
height = re.sub("[^0-9]", "", height)
|
||||
width = float(re.sub("[^0-9]", "", width))
|
||||
height = float(re.sub("[^0-9]", "", height))
|
||||
print("\n width / height")
|
||||
print(width, height)
|
||||
|
||||
width = float(width)
|
||||
height = float(height)
|
||||
if autoScale:
|
||||
|
||||
# scale_x = bed_max_x / max(width, height)
|
||||
scale_x = min(bed_max_x / max(width, height),bed_max_y / max(width, height))
|
||||
# scale_y = bed_max_y / max(width, height)
|
||||
# scale_x = min(scale_x, scale_y)
|
||||
# scale_y = scale_x
|
||||
#
|
||||
scale_y = scale_x
|
||||
|
||||
else:
|
||||
|
||||
scale_x = 1
|
||||
scale_y = 1
|
||||
|
||||
print("scale factor: ", scale_y)
|
||||
|
||||
if debug:
|
||||
print("\n preamble")
|
||||
print(preamble)
|
||||
commands.append(preamble)
|
||||
|
||||
commands.append(header)
|
||||
commands.append("(begin)")
|
||||
for i in [f"{feed_rate}", "G90"]:
|
||||
commands.append(i)
|
||||
commands.append(preamble)
|
||||
|
||||
commands.append(f"F{feed_rate}")
|
||||
print("\n begin main loop")
|
||||
|
||||
for elem in root.iter():
|
||||
|
||||
if debug:
|
||||
print("\nelem")
|
||||
print("\n\n\n***************** elem ******************")
|
||||
print(elem)
|
||||
|
||||
try:
|
||||
@@ -105,7 +110,15 @@ def generate_gcode(path):
|
||||
commands.append(i) # add tag name ad comment
|
||||
|
||||
shape_class = getattr(shapes_pkg, tag_suffix)
|
||||
if debug:
|
||||
print("\n shape_class")
|
||||
print(shape_class)
|
||||
|
||||
shape_obj = shape_class(elem)
|
||||
if debug:
|
||||
print("\n shape_obj")
|
||||
#print(shape_obj)
|
||||
|
||||
d = shape_obj.d_path()
|
||||
|
||||
m = shape_obj.transformation_matrix() # todo work out what d and m are
|
||||
@@ -129,23 +142,20 @@ def generate_gcode(path):
|
||||
for x, y in p:
|
||||
|
||||
if first:
|
||||
first = (x, y)
|
||||
# commands.append("G0 X%0.1f Y%0.1f Z%0.1f" %(scale_x*x, scale_y*y, zTravel))
|
||||
command = g_string(x, y, zTravel, "G0", precision)
|
||||
|
||||
command = g_string(x * scale_x, (-y+height) * scale_y, zTravel, "G0", precision) #todo why do i need to flip?
|
||||
commands.append(command)
|
||||
if debug:
|
||||
print(command)
|
||||
first = False
|
||||
|
||||
# if x > 0 and x < bed_max_x and y > 0 and y < bed_max_y:
|
||||
|
||||
# commands.append("G1 X%0.3f Y%0.3f Z%0.3f" % (scale_x*x, scale_y*y, zDraw))
|
||||
command = g_string(x, y, zDraw, "G1", precision)
|
||||
command = g_string(x * scale_x, (-y+height) * scale_y, zDraw, "G1", precision)
|
||||
commands.append(command)
|
||||
# else:
|
||||
# print("out of bed")
|
||||
if debug:
|
||||
print(command)
|
||||
|
||||
# count += 1
|
||||
|
||||
# commands.append("G0 Z%0.1f" %zTravel)
|
||||
command = g_string(x, y, zTravel, "G0", precision)
|
||||
commands.append(command)
|
||||
|
||||
@@ -166,13 +176,44 @@ def g_string(x, y, z=False, prefix="G1", p=3):
|
||||
return f"{prefix} X{x:.{p}f} Y{y:.{p}f}"
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
c = generate_gcode(path)
|
||||
# if __name__ == "__main__":
|
||||
# c = generate_gcode(path)
|
||||
# # for i in c:
|
||||
# # print(i)
|
||||
#
|
||||
# with open(output, 'w+') as output_file:
|
||||
# for i in c:
|
||||
# print(i)
|
||||
# output_file.write(i + "\n")
|
||||
#
|
||||
# print("done")
|
||||
|
||||
with open(output, 'w+') as output_file:
|
||||
for i in c:
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
|
||||
if len(sys.argv) < 3:
|
||||
print("usage: python convert.py source.svg destination.gcode")
|
||||
sys.exit()
|
||||
|
||||
source = sys.argv[1]
|
||||
target = sys.argv[2]
|
||||
|
||||
|
||||
|
||||
print("converting!")
|
||||
|
||||
print(source, target)
|
||||
|
||||
with open(target, 'w+') as output_file:
|
||||
g = generate_gcode(source)
|
||||
for i in g:
|
||||
output_file.write(i + "\n")
|
||||
|
||||
print("done")
|
||||
print("done!")
|
||||
+652789
File diff suppressed because it is too large.
Load diff
Reference in new issue
Block a user