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 for path in self.paths:
43 if not path.isClosed():
46 def _checkForNewPath(self, type, obj):
48 if self._lastLine is not None and self._lastLinePoint == complex(float(obj[10]), float(obj[20])):
49 self._lastLine.addLineTo(float(obj[11]), float(obj[21]))
51 p = self.addPath(float(obj[10]), float(obj[20]))
52 p.addLineTo(float(obj[11]), float(obj[21]))
54 self._lastLinePoint = complex(float(obj[11]), float(obj[21]))
55 elif type == 'POLYLINE':
57 elif type == 'VERTEX':
58 if self._polyLine is None:
59 self._polyLine = self.addPath(float(obj[10]), float(obj[20]))
61 self._polyLine.addLineTo(float(obj[10]), float(obj[20]))
65 if __name__ == '__main__':
66 for n in xrange(1, len(sys.argv)):
67 print 'File: %s' % (sys.argv[n])
68 dxf = DXF(sys.argv[n])
70 dxf.saveAsHtml("test_export.html")