Able to generate g-code

This commit is contained in:
Vishal Patil committed 2013-12-18 16:29:39 -05:00
1 parent 9eb93d547d
commit 7e8a4943b9
2 files changed
+21 -21

No files matched your search

+7 -8
View File
@@ -9,19 +9,18 @@
<dependency type="executable" location="extensions">shapes.py</dependency>
<dependency type="executable" location="extensions">simplepath.py</dependency>
<dependency type="executable" location="extensions">svg2gcode.py</dependency>
<param name="bed-width" type="int" _gui-text="Bed Width">200</param>
<param name="bed-height" type="int" _gui-text="Bed Height">200</param>
<param name="bed-width" type="int" min="200" max="200" _gui-text="Bed Width">200</param>
<param name="bed-height" type="int" min="200" max="200" _gui-text="Bed Height">200</param>
<param name="gcode-file" type="string" _gui-text="G-code path">plastibot.gcode</param>
<param name="preamble" type="String" _gui-text="Preamble">"G28\nG1 Z5.0"</param>
<param name="postamble" type="String" _gui-text="Postamble">"G28"</param>
<param name="shape-preamble" type="String" _gui-text="Shape Preamble">"G4 P200"</param>
<param name="shape-postamble" type="String" _gui-text="Shape Postamble">"G4
P200"</param>
<param name="preamble" type="string" _gui-text="Preamble">G28\nG1 Z5.0</param>
<param name="postamble" type="string" _gui-text="Postamble">G28</param>
<param name="shape-preamble" type="string" _gui-text="Shape Preamble">G4 P200</param>
<param name="shape-postamble" type="string" _gui-text="Shape Postamble">G4 P200</param>
<effect>
<object-type>all</object-type>
<effects-menu>
<submenu _name="Plastibot"/>
<submenu _name="svg2gcode"/>
</effects-menu>
</effect>
<script>
+14 -13
View File
@@ -34,8 +34,13 @@ class svg2gcode(inkex.Effect):
type = 'string', dest = 'shape_postamble', default = 'G4 P200\n',
help = 'Shape Postamble G-code')
def generate_gcode(svg):
def generate_gcode(self, svg):
gcode_file = os.path.join(os.path.expanduser('~'), self.options.gcode_file)
try:
os.remove(gcode_file)
except OSError:
pass
bed_width = self.options.bed_width
bed_height = self.options.bed_height
@@ -48,13 +53,12 @@ class svg2gcode(inkex.Effect):
scale_x = bed_width / max(width, height)
scale_y = bed_height / max(width, height)
with open(gcode_file) as gcode:
with open(gcode_file, 'w') as gcode:
gcode.write(self.options.preamble + '\n')
svg_shapes = set(['rect', 'circle', 'ellipse', 'line', 'polyline', 'polygon', 'path'])
for elem in svg.iter():
try:
_, tag_suffix = elem.tag.split('}')
except ValueError:
@@ -67,37 +71,34 @@ class svg2gcode(inkex.Effect):
if d:
gcode.write(self.options.shape_preamble + '\n')
p = point_generator(d, smoothness)
p = point_generator(d, 0.2)
for x,y in p:
if x > 0 and x < bed_width and y > 0 and y < bed_height:
gcode.write("G1 X%0.1f Y%0.1f\n" % (scale_x*x, scale_y*y))
gcode.write("G1 X%0.1f Y%0.1f\n" % (scale_x*x, scale_y*y))
gcode.write(self.options.shape_postamble + '\n')
gcode.write(self.options.postamble + '\n')
gcode.write(self.options.postamble + '\n')
def effect(self):
svg = self.document.getroot()
self.generate_gcode(svg)
width = inkex.unittouu(svg.get('width'))
height = inkex.unittouu(svg.attrib['height'])
layer = inkex.etree.SubElement(svg, 'g')
layer.set(inkex.addNS('label', 'inkscape'), 'Hello %s Layer' % (what))
layer.set(inkex.addNS('label', 'inkscape'), 'Hello svg2gcode Layer')
layer.set(inkex.addNS('groupmode', 'inkscape'), 'layer')
# Create text element
text = inkex.etree.Element(inkex.addNS('text','svg'))
text.text = 'Hello %s!' % (what)
text.text = 'Hello svg2gcode!'
# Set text position to center of document.
text.set('x', str(width / 2))
text.set('y', str(height / 2))
# Center text horizontally with CSS style.
style = {'text-align' : 'center', 'text-anchor': 'middle'}
text.set('style', formatStyle(style))
# Connect elements together.
layer.append(text)