1 from __future__ import absolute_import
2 __copyright__ = "Copyright (C) 2013 David Braam - Released under terms of the AGPLv3 License"
8 from xml.etree import ElementTree
10 from Cura.util.drawingLoader import drawing
12 class DXF(drawing.Drawing):
13 def __init__(self, filename):
14 super(DXF, self).__init__()
18 entityType = 'UNKNOWN'
19 sectionName = 'UNKNOWN'
21 f = open(filename, "r")
23 groupCode = f.readline().strip()
26 groupCode = int(groupCode)
27 value = f.readline().strip()
29 if sectionName == 'ENTITIES':
30 self._checkForNewPath(entityType, activeObject)
33 elif entityType == 'SECTION':
37 activeObject[groupCode] = value
38 if sectionName == 'ENTITIES':
39 self._checkForNewPath(entityType, activeObject)
42 self._postProcessPaths()
44 def _checkForNewPath(self, type, obj):
46 if self._lastLine is not None and self._lastLinePoint == complex(float(obj[10]), float(obj[20])):
47 self._lastLine.addLineTo(float(obj[11]), float(obj[21]))
49 p = self.addPath(float(obj[10]), float(obj[20]))
50 p.addLineTo(float(obj[11]), float(obj[21]))
52 self._lastLinePoint = complex(float(obj[11]), float(obj[21]))
53 elif type == 'POLYLINE':
55 elif type == 'VERTEX':
56 if self._polyLine is None:
57 self._polyLine = self.addPath(float(obj[10]), float(obj[20]))
59 self._polyLine.addLineTo(float(obj[10]), float(obj[20]))
63 if __name__ == '__main__':
64 for n in xrange(1, len(sys.argv)):
65 print 'File: %s' % (sys.argv[n])
66 dxf = DXF(sys.argv[n])
68 dxf.saveAsHtml("test_export.html")