diff --git a/FlatCAMApp.py b/FlatCAMApp.py index 76c72876..e0dac238 100644 --- a/FlatCAMApp.py +++ b/FlatCAMApp.py @@ -1599,9 +1599,8 @@ class App(QtCore.QObject): return # Check for more compatible types and add as required - # Excellon not yet supported, there seems to be a list within the Polygon Geometry that shapely's svg export doesn't like - - if (not isinstance(obj, FlatCAMGeometry) and not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMCNCjob)): + if (not isinstance(obj, FlatCAMGeometry) and not isinstance(obj, FlatCAMGerber) and not isinstance(obj, FlatCAMCNCjob) + and not isinstance(obj, FlatCAMExcellon)): msg = "ERROR: Only Geometry, Gerber and CNCJob objects can be used." msgbox = QtGui.QMessageBox() msgbox.setInformativeText(msg) @@ -1729,11 +1728,18 @@ class App(QtCore.QObject): with self.proc_container.new("Exporting SVG") as proc: exported_svg = obj.export_svg() + # Sometimes obj.solid_geometry can be a list instead of a Shapely class + # Make sure we see it as a Shapely Geometry class + geom = obj.solid_geometry + if type(obj.solid_geometry) is list: + geom = [cascaded_union(obj.solid_geometry)][0] + + # Determine bounding area for svg export - svgwidth = obj.solid_geometry.bounds[2] - obj.solid_geometry.bounds[0] - svgheight = obj.solid_geometry.bounds[3] - obj.solid_geometry.bounds[1] - minx = obj.solid_geometry.bounds[0] - miny = obj.solid_geometry.bounds[1] - svgheight + svgwidth = geom.bounds[2] - geom.bounds[0] + svgheight = geom.bounds[3] - geom.bounds[1] + minx = geom.bounds[0] + miny = geom.bounds[1] - svgheight # Convert everything to strings for use in the xml doc svgwidth = str(svgwidth) diff --git a/camlib.py b/camlib.py index e59b18c0..9cd11e96 100644 --- a/camlib.py +++ b/camlib.py @@ -875,7 +875,14 @@ class Geometry(object): :return: SVG Element """ - svg_elem = self.solid_geometry.svg(scale_factor=0.05) + # Sometimes self.solid_geometry can be a list instead of a Shapely class + # Make sure we see it as a Shapely Geometry class + geom = self.solid_geometry + if type(self.solid_geometry) is list: + geom = [cascaded_union(self.solid_geometry)][0] + + # Convert to a SVG + svg_elem = geom.svg(scale_factor=0.05) return svg_elem class ApertureMacro: @@ -3345,14 +3352,19 @@ class CNCjob(Geometry): self.solid_geometry = cascaded_union([geo['geom'] for geo in self.gcode_parsed]) # Convert the cuts and travels into single geometry objects we can render as svg xml - travelsgeom = cascaded_union([geo['geom'] for geo in travels]) - cutsgeom = cascaded_union([geo['geom'] for geo in cuts]) + if travels: + travelsgeom = cascaded_union([geo['geom'] for geo in travels]) + if cuts: + cutsgeom = cascaded_union([geo['geom'] for geo in cuts]) # Render the SVG Xml # The scale factor affects the size of the lines, and the stroke color adds different formatting for each set # It's better to have the travels sitting underneath the cuts for visicut - svg_elem = travelsgeom.svg(scale_factor=scale, stroke_color="#F0E24D") - svg_elem += cutsgeom.svg(scale_factor=scale, stroke_color="#5E6CFF") + svg_elem = "" + if travels: + svg_elem = travelsgeom.svg(scale_factor=scale, stroke_color="#F0E24D") + if cuts: + svg_elem += cutsgeom.svg(scale_factor=scale, stroke_color="#5E6CFF") return svg_elem