points to mm conversion
This commit is contained in:
1 parent
9a2fc02162
commit
fb5cdde05b
4 files changed
+43
-7
No files matched your search
@@ -16,6 +16,9 @@ _copy 's2g' to your path and run from anywhere_
|
||||
|
||||
**There is a brute force path optimisation algarithm. Very slow for large files, can be disabled in config.py**
|
||||
|
||||
*illustrator exports in points* regardless of your document settings
|
||||
if units are set to points in the config file, we convert to mm on the fly
|
||||
|
||||
There are various settings you can change in config.py. Most notably, you must set an upper and lower position for the z axis.
|
||||
|
||||
zTravel is the height it will move to before traveling to the next stroke
|
||||
|
||||
@@ -41,7 +41,14 @@ precision = 2
|
||||
|
||||
|
||||
""" scale gcode to fit bed size"""
|
||||
auto_scale = True
|
||||
auto_scale = False
|
||||
|
||||
""" optimize path - slow for large files"""
|
||||
optimise = True
|
||||
optimise = True
|
||||
|
||||
"""
|
||||
illustrator exports svg's in points, not mm
|
||||
set to "mm" if you don't want to convert to mm
|
||||
"""
|
||||
units = "points"
|
||||
#units = "mm"
|
||||
@@ -9,6 +9,7 @@ def get_distance(a, b, sq=False):
|
||||
|
||||
x = x2 - x1
|
||||
y = y2 - y1
|
||||
|
||||
if sq:
|
||||
return sqrt(x * x + y * y)
|
||||
else:
|
||||
|
||||
+30
-5
@@ -23,11 +23,12 @@ def get_shapes(path, auto_scale=True):
|
||||
shapes = []
|
||||
tree = ET.parse(path)
|
||||
root = tree.getroot()
|
||||
|
||||
pointRatio = 0.352778
|
||||
|
||||
width = root.get('width')
|
||||
height = root.get('height')
|
||||
|
||||
|
||||
|
||||
if width is None or height is None:
|
||||
viewbox = root.get('viewBox')
|
||||
if viewbox:
|
||||
@@ -37,8 +38,15 @@ def get_shapes(path, auto_scale=True):
|
||||
print("Unable to get width and height for the svg")
|
||||
sys.exit(1)
|
||||
|
||||
width = float(re.sub("[^0-9]", "", width))
|
||||
height = float(re.sub("[^0-9]", "", height))
|
||||
# width = float(re.sub("[^0-9]", "", width))
|
||||
# height = float(re.sub("[^0-9]", "", height))
|
||||
|
||||
width = float(width)
|
||||
height = float(height)
|
||||
|
||||
if units == "points":
|
||||
width *= pointRatio
|
||||
height *= pointRatio
|
||||
|
||||
if auto_scale:
|
||||
print("\nauto scaling")
|
||||
@@ -76,6 +84,11 @@ def get_shapes(path, auto_scale=True):
|
||||
|
||||
for x, y in p: # todo sort out this nightmare
|
||||
|
||||
if units == "points":
|
||||
|
||||
x *= pointRatio
|
||||
y *= pointRatio
|
||||
|
||||
y = -y + height
|
||||
|
||||
if auto_scale:
|
||||
@@ -114,8 +127,13 @@ def g_string(x, y, z=False, prefix="G1", p=3):
|
||||
def shapes_2_gcode(shapes):
|
||||
|
||||
t1 = dt.now()
|
||||
commands = []
|
||||
with open("header.txt") as h:
|
||||
header = h.read()
|
||||
|
||||
commands = [f"{header}", f'F{feed_rate}']
|
||||
|
||||
for i in shapes:
|
||||
commands += ['', shape_preamble, ""]
|
||||
|
||||
commands.append(g_string(i[0][0], i[0][1], zTravel, "G0"))
|
||||
|
||||
@@ -124,6 +142,13 @@ def shapes_2_gcode(shapes):
|
||||
|
||||
commands.append(g_string(i[-1][0], i[-1][1], zTravel, "G0"))
|
||||
|
||||
commands += ["", shape_postamble, ""]
|
||||
|
||||
commands += [" ",postamble, ""]
|
||||
|
||||
commands += ["(home)", f"G0 {zTravel}", f"G0 X0 Y0"]
|
||||
|
||||
|
||||
timer(t1, "shapes_2_gcode ")
|
||||
return commands
|
||||
|
||||
|
||||
Reference in new issue
Block a user