1 #!/usr/bin/env python
2 '''
3 dxf_input.py - input a DXF file >= (AutoCAD Release 13 == AC1012)
5 Copyright (C) 2008, 2009 Alvin Penner, penner@vaxxine.com
6 Copyright (C) 2009 Christian Mayer, inkscape@christianmayer.de
7 - thanks to Aaron Spike for inkex.py and simplestyle.py
8 - without which this would not have been possible
10 This program is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 '''
25 import inkex, simplestyle, math
26 from StringIO import StringIO
27 from urllib import quote
29 def export_MTEXT():
30 # mandatory group codes : (1 or 3, 10, 20) (text, x, y)
31 if (vals[groups['1']] or vals[groups['3']]) and vals[groups['10']] and vals[groups['20']]:
32 x = vals[groups['10']][0]
33 y = vals[groups['20']][0]
34 # optional group codes : (21, 40, 50) (direction, text height mm, text angle)
35 size = 12 # default fontsize in px
36 if vals[groups['40']]:
37 size = scale*vals[groups['40']][0]
38 attribs = {'x': '%f' % x, 'y': '%f' % y, 'style': 'font-size: %.1fpx; fill: %s' % (size, color)}
39 angle = 0 # default angle in degrees
40 if vals[groups['50']]:
41 angle = vals[groups['50']][0]
42 attribs.update({'transform': 'rotate (%f %f %f)' % (-angle, x, y)})
43 elif vals[groups['21']]:
44 if vals[groups['21']][0] == 1.0:
45 attribs.update({'transform': 'rotate (%f %f %f)' % (-90, x, y)})
46 elif vals[groups['21']][0] == -1.0:
47 attribs.update({'transform': 'rotate (%f %f %f)' % (90, x, y)})
48 attribs.update({inkex.addNS('linespacing','sodipodi'): '125%'})
49 node = inkex.etree.SubElement(layer, 'text', attribs)
50 text = ''
51 if vals[groups['3']]:
52 for i in range (0, len(vals[groups['3']])):
53 text += vals[groups['3']][i]
54 if vals[groups['1']]:
55 text += vals[groups['1']][0]
56 found = text.find('\P') # new line
57 while found > -1:
58 tspan = inkex.etree.SubElement(node , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})
59 tspan.text = text[:found]
60 text = text[(found+2):]
61 found = text.find('\P')
62 tspan = inkex.etree.SubElement(node , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})
63 tspan.text = text
65 def export_POINT():
66 # mandatory group codes : (10, 20) (x, y)
67 if vals[groups['10']] and vals[groups['20']]:
68 generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], w/2, 0.0, 1.0, 0.0, 0.0)
70 def export_LINE():
71 # mandatory group codes : (10, 11, 20, 21) (x1, x2, y1, y2)
72 if vals[groups['10']] and vals[groups['11']] and vals[groups['20']] and vals[groups['21']]:
73 path = 'M %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], scale*(vals[groups['11']][0] - xmin), - scale*(vals[groups['21']][0] - ymax))
74 attribs = {'d': path, 'style': style}
75 inkex.etree.SubElement(layer, 'path', attribs)
77 def export_SPLINE():
78 # mandatory group codes : (10, 20, 70) (x, y, flags)
79 if vals[groups['10']] and vals[groups['20']] and vals[groups['70']]:
80 if not (vals[groups['70']][0] & 3) and len(vals[groups['10']]) == 4 and len(vals[groups['20']]) == 4:
81 path = 'M %f,%f C %f,%f %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][1], vals[groups['20']][1], vals[groups['10']][2], vals[groups['20']][2], vals[groups['10']][3], vals[groups['20']][3])
82 attribs = {'d': path, 'style': style}
83 inkex.etree.SubElement(layer, 'path', attribs)
84 if not (vals[groups['70']][0] & 3) and len(vals[groups['10']]) == 3 and len(vals[groups['20']]) == 3:
85 path = 'M %f,%f Q %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][1], vals[groups['20']][1], vals[groups['10']][2], vals[groups['20']][2])
86 attribs = {'d': path, 'style': style}
87 inkex.etree.SubElement(layer, 'path', attribs)
89 def export_CIRCLE():
90 # mandatory group codes : (10, 20, 40) (x, y, radius)
91 if vals[groups['10']] and vals[groups['20']] and vals[groups['40']]:
92 generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], scale*vals[groups['40']][0], 0.0, 1.0, 0.0, 0.0)
94 def export_ARC():
95 # mandatory group codes : (10, 20, 40, 50, 51) (x, y, radius, angle1, angle2)
96 if vals[groups['10']] and vals[groups['20']] and vals[groups['40']] and vals[groups['50']] and vals[groups['51']]:
97 generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], scale*vals[groups['40']][0], 0.0, 1.0, vals[groups['50']][0]*math.pi/180.0, vals[groups['51']][0]*math.pi/180.0)
99 def export_ELLIPSE():
100 # mandatory group codes : (10, 11, 20, 21, 40, 41, 42) (xc, xm, yc, ym, width ratio, angle1, angle2)
101 if vals[groups['10']] and vals[groups['11']] and vals[groups['20']] and vals[groups['21']] and vals[groups['40']] and vals[groups['41']] and vals[groups['42']]:
102 generate_ellipse(vals[groups['10']][0], vals[groups['20']][0], scale*vals[groups['11']][0], scale*vals[groups['21']][0], vals[groups['40']][0], vals[groups['41']][0], vals[groups['42']][0])
104 def export_LEADER():
105 # mandatory group codes : (10, 20) (x, y)
106 if vals[groups['10']] and vals[groups['20']]:
107 if len(vals[groups['10']]) > 1 and len(vals[groups['20']]) == len(vals[groups['10']]):
108 path = 'M %f,%f' % (vals[groups['10']][0], vals[groups['20']][0])
109 for i in range (1, len(vals[groups['10']])):
110 path += ' %f,%f' % (vals[groups['10']][i], vals[groups['20']][i])
111 attribs = {'d': path, 'style': style}
112 inkex.etree.SubElement(layer, 'path', attribs)
114 def export_LWPOLYLINE():
115 # mandatory group codes : (10, 20, 70) (x, y, flags)
116 if vals[groups['10']] and vals[groups['20']] and vals[groups['70']]:
117 if len(vals[groups['10']]) > 1 and len(vals[groups['20']]) == len(vals[groups['10']]):
118 # optional group codes : (42) (bulge)
119 iseqs = 0
120 ibulge = 0
121 while seqs[iseqs] != '20':
122 iseqs += 1
123 path = 'M %f,%f' % (vals[groups['10']][0], vals[groups['20']][0])
124 xold = vals[groups['10']][0]
125 yold = vals[groups['20']][0]
126 for i in range (1, len(vals[groups['10']])):
127 bulge = 0
128 iseqs += 1
129 while seqs[iseqs] != '20':
130 if seqs[iseqs] == '42':
131 bulge = vals[groups['42']][ibulge]
132 ibulge += 1
133 iseqs += 1
134 if bulge:
135 sweep = 0 # sweep CCW
136 if bulge < 0:
137 sweep = 1 # sweep CW
138 bulge = -bulge
139 large = 0 # large-arc-flag
140 if bulge > 1:
141 large = 1
142 r = math.sqrt((vals[groups['10']][i] - xold)**2 + (vals[groups['20']][i] - yold)**2)
143 r = 0.25*r*(bulge + 1.0/bulge)
144 path += ' A %f,%f 0.0 %d %d %f,%f' % (r, r, large, sweep, vals[groups['10']][i], vals[groups['20']][i])
145 else:
146 path += ' L %f,%f' % (vals[groups['10']][i], vals[groups['20']][i])
147 xold = vals[groups['10']][i]
148 yold = vals[groups['20']][i]
149 if vals[groups['70']][0] == 1: # closed path
150 path += ' z'
151 attribs = {'d': path, 'style': style}
152 inkex.etree.SubElement(layer, 'path', attribs)
154 def export_HATCH():
155 # mandatory group codes : (10, 20, 70, 72, 92, 93) (x, y, fill, Edge Type, Path Type, Number of edges)
156 if vals[groups['10']] and vals[groups['20']] and vals[groups['70']] and vals[groups['72']] and vals[groups['92']] and vals[groups['93']]:
157 if vals[groups['70']][0] and len(vals[groups['10']]) > 1 and len(vals[groups['20']]) == len(vals[groups['10']]):
158 # optional group codes : (11, 21, 40, 50, 51, 73) (x, y, r, angle1, angle2, CCW)
159 i10 = 1 # count start points
160 i11 = 0 # count line end points
161 i40 = 0 # count circles
162 i72 = 0 # count edge type flags
163 path = ''
164 for i in range (0, len(vals[groups['93']])):
165 xc = vals[groups['10']][i10]
166 yc = vals[groups['20']][i10]
167 if vals[groups['72']][i72] == 2: # arc
168 rm = scale*vals[groups['40']][i40]
169 a1 = vals[groups['50']][i40]
170 path += 'M %f,%f ' % (xc + rm*math.cos(a1*math.pi/180.0), yc + rm*math.sin(a1*math.pi/180.0))
171 else:
172 a1 = 0
173 path += 'M %f,%f ' % (xc, yc)
174 for j in range(0, vals[groups['93']][i]):
175 if vals[groups['92']][i] & 2: # polyline
176 if j > 0:
177 path += 'L %f,%f ' % (vals[groups['10']][i10], vals[groups['20']][i10])
178 if j == vals[groups['93']][i] - 1:
179 i72 += 1
180 elif vals[groups['72']][i72] == 2: # arc
181 xc = vals[groups['10']][i10]
182 yc = vals[groups['20']][i10]
183 rm = scale*vals[groups['40']][i40]
184 a2 = vals[groups['51']][i40]
185 diff = (a2 - a1 + 360) % (360)
186 sweep = 1 - vals[groups['73']][i40] # sweep CCW
187 large = 0 # large-arc-flag
188 if diff:
189 path += 'A %f,%f 0.0 %d %d %f,%f ' % (rm, rm, large, sweep, xc + rm*math.cos(a2*math.pi/180.0), yc + rm*math.sin(a2*math.pi/180.0))
190 else:
191 path += 'A %f,%f 0.0 %d %d %f,%f ' % (rm, rm, large, sweep, xc + rm*math.cos((a1+180.0)*math.pi/180.0), yc + rm*math.sin((a1+180.0)*math.pi/180.0))
192 path += 'A %f,%f 0.0 %d %d %f,%f ' % (rm, rm, large, sweep, xc + rm*math.cos(a1*math.pi/180.0), yc + rm*math.sin(a1*math.pi/180.0))
193 i40 += 1
194 i72 += 1
195 elif vals[groups['72']][i72] == 1: # line
196 path += 'L %f,%f ' % (scale*(vals[groups['11']][i11] - xmin), -scale*(vals[groups['21']][i11] - ymax))
197 i11 += 1
198 i72 += 1
199 i10 += 1
200 path += "z "
201 style = simplestyle.formatStyle({'fill': '%s' % color})
202 attribs = {'d': path, 'style': style}
203 inkex.etree.SubElement(layer, 'path', attribs)
205 def export_DIMENSION():
206 # mandatory group codes : (10, 11, 13, 14, 20, 21, 23, 24) (x1..4, y1..4)
207 if vals[groups['10']] and vals[groups['11']] and vals[groups['13']] and vals[groups['14']] and vals[groups['20']] and vals[groups['21']] and vals[groups['23']] and vals[groups['24']]:
208 dx = abs(vals[groups['10']][0] - vals[groups['13']][0])
209 dy = abs(vals[groups['20']][0] - vals[groups['23']][0])
210 if (vals[groups['10']][0] == vals[groups['14']][0]) and dx > 0.00001:
211 d = dx/scale
212 dy = 0
213 path = 'M %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['13']][0], vals[groups['20']][0])
214 elif (vals[groups['20']][0] == vals[groups['24']][0]) and dy > 0.00001:
215 d = dy/scale
216 dx = 0
217 path = 'M %f,%f %f,%f' % (vals[groups['10']][0], vals[groups['20']][0], vals[groups['10']][0], vals[groups['23']][0])
218 else:
219 return
220 attribs = {'d': path, 'style': style + '; marker-start: url(#DistanceX); marker-end: url(#DistanceX)'}
221 inkex.etree.SubElement(layer, 'path', attribs)
222 x = scale*(vals[groups['11']][0] - xmin)
223 y = - scale*(vals[groups['21']][0] - ymax)
224 size = 12 # default fontsize in px
225 if vals[groups['3']]:
226 if DIMTXT.has_key(vals[groups['3']][0]):
227 size = scale*DIMTXT[vals[groups['3']][0]]
228 if size < 2:
229 size = 2
230 attribs = {'x': '%f' % x, 'y': '%f' % y, 'style': 'font-size: %.1fpx; fill: %s' % (size, color)}
231 if dx == 0:
232 attribs.update({'transform': 'rotate (%f %f %f)' % (-90, x, y)})
233 node = inkex.etree.SubElement(layer, 'text', attribs)
234 tspan = inkex.etree.SubElement(node , 'tspan', {inkex.addNS('role','sodipodi'): 'line'})
235 tspan.text = str(float('%.2f' % d))
237 def export_INSERT():
238 # mandatory group codes : (2, 10, 20) (block name, x, y)
239 if vals[groups['2']] and vals[groups['10']] and vals[groups['20']]:
240 x = vals[groups['10']][0]
241 y = vals[groups['20']][0] - scale*ymax
242 attribs = {'x': '%f' % x, 'y': '%f' % y, inkex.addNS('href','xlink'): '#' + quote(vals[groups['2']][0].encode("utf-8"))}
243 inkex.etree.SubElement(layer, 'use', attribs)
245 def export_BLOCK():
246 # mandatory group codes : (2) (block name)
247 if vals[groups['2']]:
248 global block
249 block = inkex.etree.SubElement(defs, 'symbol', {'id': vals[groups['2']][0]})
251 def export_ENDBLK():
252 global block
253 block = defs # initiallize with dummy
255 def export_ATTDEF():
256 # mandatory group codes : (1, 2) (default, tag)
257 if vals[groups['1']] and vals[groups['2']]:
258 vals[groups['1']][0] = vals[groups['2']][0]
259 export_MTEXT()
261 def generate_ellipse(xc, yc, xm, ym, w, a1, a2):
262 rm = math.sqrt(xm*xm + ym*ym)
263 a = math.atan2(ym, xm)
264 diff = (a2 - a1 + 2*math.pi) % (2*math.pi)
265 if abs(diff) > 0.0000001 and abs(diff - 2*math.pi) > 0.0000001: # open arc
266 large = 0 # large-arc-flag
267 if diff > math.pi:
268 large = 1
269 xt = rm*math.cos(a1)
270 yt = w*rm*math.sin(a1)
271 x1 = xt*math.cos(a) - yt*math.sin(a)
272 y1 = xt*math.sin(a) + yt*math.cos(a)
273 xt = rm*math.cos(a2)
274 yt = w*rm*math.sin(a2)
275 x2 = xt*math.cos(a) - yt*math.sin(a)
276 y2 = xt*math.sin(a) + yt*math.cos(a)
277 path = 'M %f,%f A %f,%f %f %d 0 %f,%f' % (xc+x1, yc-y1, rm, w*rm, -180.0*a/math.pi, large, xc+x2, yc-y2)
278 else: # closed arc
279 path = 'M %f,%f A %f,%f %f 1 0 %f,%f %f,%f %f 1 0 %f,%f z' % (xc+xm, yc-ym, rm, w*rm, -180.0*a/math.pi, xc-xm, yc+ym, rm, w*rm, -180.0*a/math.pi, xc+xm, yc-ym)
280 attribs = {'d': path, 'style': style}
281 inkex.etree.SubElement(layer, 'path', attribs)
283 def get_line():
284 return (stream.readline().strip(), stream.readline().strip())
286 def get_group(group):
287 line = get_line()
288 if line[0] == group:
289 return float(line[1])
290 else:
291 return 0.0
293 # define DXF Entities and specify which Group Codes to monitor
295 entities = {'MTEXT': export_MTEXT, 'TEXT': export_MTEXT, 'POINT': export_POINT, 'LINE': export_LINE, 'SPLINE': export_SPLINE, 'CIRCLE': export_CIRCLE, 'ARC': export_ARC, 'ELLIPSE': export_ELLIPSE, 'LEADER': export_LEADER, 'LWPOLYLINE': export_LWPOLYLINE, 'HATCH': export_HATCH, 'DIMENSION': export_DIMENSION, 'INSERT': export_INSERT, 'BLOCK': export_BLOCK, 'ENDBLK': export_ENDBLK, 'ATTDEF': export_ATTDEF, 'DICTIONARY': False}
296 groups = {'1': 0, '2': 1, '3': 2, '6': 3, '8': 4, '10': 5, '11': 6, '13': 7, '14': 8, '20': 9, '21': 10, '23': 11, '24': 12, '40': 13, '41': 14, '42': 15, '50': 16, '51': 17, '62': 18, '70': 19, '72': 20, '73': 21, '92': 22, '93': 23, '370': 24}
297 colors = { 1: '#FF0000', 2: '#FFFF00', 3: '#00FF00', 4: '#00FFFF', 5: '#0000FF',
298 6: '#FF00FF', 8: '#414141', 9: '#808080', 12: '#BD0000', 30: '#FF7F00',
299 250: '#333333', 251: '#505050', 252: '#696969', 253: '#828282', 254: '#BEBEBE', 255: '#FFFFFF'}
301 parser = inkex.optparse.OptionParser(usage="usage: %prog [options] SVGfile", option_class=inkex.InkOption)
302 parser.add_option("--auto", action="store", type="inkbool", dest="auto", default=True)
303 parser.add_option("--scale", action="store", type="string", dest="scale", default="1.0")
304 parser.add_option("--encoding", action="store", type="string", dest="input_encode", default="latin_1")
305 parser.add_option("--tab", action="store", type="string", dest="tab", default="Options")
306 parser.add_option("--inputhelp", action="store", type="string", dest="inputhelp", default="")
307 (options, args) = parser.parse_args(inkex.sys.argv[1:])
308 doc = inkex.etree.parse(StringIO('<svg xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"></svg>'))
309 desc = inkex.etree.SubElement(doc.getroot(), 'desc', {})
310 defs = inkex.etree.SubElement(doc.getroot(), 'defs', {})
311 marker = inkex.etree.SubElement(defs, 'marker', {'id': 'DistanceX', 'orient': 'auto', 'refX': '0.0', 'refY': '0.0', 'style': 'overflow:visible'})
312 inkex.etree.SubElement(marker, 'path', {'d': 'M 3,-3 L -3,3 M 0,-5 L 0,5', 'style': 'stroke:#000000; stroke-width:0.5'})
313 stream = open(args[0], 'r')
314 xmax = xmin = 0.0
315 ymax = 297.0 # default A4 height in mm
316 line = get_line()
317 flag = 0 # (0, 1, 2, 3) = (none, LAYER, LTYPE, DIMTXT)
318 layer_colors = {} # store colors by layer
319 layer_nodes = {} # store nodes by layer
320 linetypes = {} # store linetypes by name
321 DIMTXT = {} # store DIMENSION text sizes
323 while line[0] and line[1] != 'BLOCKS':
324 line = get_line()
325 if options.auto:
326 if line[1] == '$EXTMIN':
327 xmin = get_group('10')
328 if line[1] == '$EXTMAX':
329 xmax = get_group('10')
330 ymax = get_group('20')
331 if flag == 1 and line[0] == '2':
332 layername = unicode(line[1], options.input_encode)
333 attribs = {inkex.addNS('groupmode','inkscape'): 'layer', inkex.addNS('label','inkscape'): '%s' % layername}
334 layer_nodes[layername] = inkex.etree.SubElement(doc.getroot(), 'g', attribs)
335 if flag == 2 and line[0] == '2':
336 linename = unicode(line[1], options.input_encode)
337 linetypes[linename] = []
338 if flag == 3 and line[0] == '2':
339 stylename = unicode(line[1], options.input_encode)
340 if line[0] == '2' and line[1] == 'LAYER':
341 flag = 1
342 if line[0] == '2' and line[1] == 'LTYPE':
343 flag = 2
344 if line[0] == '2' and line[1] == 'DIMSTYLE':
345 flag = 3
346 if flag == 1 and line[0] == '62':
347 layer_colors[layername] = int(line[1])
348 if flag == 2 and line[0] == '49':
349 linetypes[linename].append(float(line[1]))
350 if flag == 3 and line[0] == '140':
351 DIMTXT[stylename] = float(line[1])
352 if line[0] == '0' and line[1] == 'ENDTAB':
353 flag = 0
355 if options.auto:
356 scale = 1.0
357 if xmax > xmin:
358 scale = 210.0/(xmax - xmin) # scale to A4 width
359 else:
360 scale = float(options.scale) # manual scale factor
361 desc.text = '%s - scale = %f' % (unicode(args[0], options.input_encode), scale)
362 scale *= 90.0/25.4 # convert from mm to pixels
364 if not layer_nodes:
365 attribs = {inkex.addNS('groupmode','inkscape'): 'layer', inkex.addNS('label','inkscape'): '0'}
366 layer_nodes['0'] = inkex.etree.SubElement(doc.getroot(), 'g', attribs)
367 layer_colors['0'] = 7
369 for linename in linetypes.keys(): # scale the dashed lines
370 linetype = ''
371 for length in linetypes[linename]:
372 linetype += '%.4f,' % math.fabs(length*scale)
373 linetypes[linename] = 'stroke-dasharray:' + linetype
375 entity = ''
376 block = defs # initiallize with dummy
377 while line[0] and line[1] != 'DICTIONARY':
378 line = get_line()
379 if entity and groups.has_key(line[0]):
380 seqs.append(line[0]) # list of group codes
381 if line[0] == '1' or line[0] == '2' or line[0] == '3' or line[0] == '6' or line[0] == '8': # text value
382 val = line[1].replace('\~', ' ')
383 val = inkex.re.sub( '\\\\A.*;', '', val)
384 val = inkex.re.sub( '\\\\H.*;', '', val)
385 val = inkex.re.sub( '\\^I', '', val)
386 val = inkex.re.sub( '{\\\\L', '', val)
387 val = inkex.re.sub( '}', '', val)
388 val = inkex.re.sub( '\\\\S.*;', '', val)
389 val = inkex.re.sub( '\\\\W.*;', '', val)
390 val = unicode(val, options.input_encode)
391 val = val.encode('unicode_escape')
392 val = inkex.re.sub( '\\\\\\\\U\+([0-9A-Fa-f]{4})', '\\u\\1', val)
393 val = val.decode('unicode_escape')
394 elif line[0] == '62' or line[0] == '70' or line[0] == '92' or line[0] == '93':
395 val = int(line[1])
396 elif line[0] == '10' or line[0] == '13' or line[0] == '14': # scaled float x value
397 val = scale*(float(line[1]) - xmin)
398 elif line[0] == '20' or line[0] == '23' or line[0] == '24': # scaled float y value
399 val = - scale*(float(line[1]) - ymax)
400 else: # unscaled float value
401 val = float(line[1])
402 vals[groups[line[0]]].append(val)
403 elif entities.has_key(line[1]):
404 if entities.has_key(entity):
405 if block != defs: # in a BLOCK
406 layer = block
407 elif vals[groups['8']]: # use Common Layer Name
408 layer = layer_nodes[vals[groups['8']][0]]
409 color = '#000000' # default color
410 if vals[groups['8']]:
411 if layer_colors.has_key(vals[groups['8']][0]):
412 if colors.has_key(layer_colors[vals[groups['8']][0]]):
413 color = colors[layer_colors[vals[groups['8']][0]]]
414 if vals[groups['62']]: # Common Color Number
415 if colors.has_key(vals[groups['62']][0]):
416 color = colors[vals[groups['62']][0]]
417 style = simplestyle.formatStyle({'stroke': '%s' % color, 'fill': 'none'})
418 w = 0.5 # default lineweight for POINT
419 if vals[groups['370']]: # Common Lineweight
420 if vals[groups['370']][0] > 0:
421 w = 90.0/25.4*vals[groups['370']][0]/100.0
422 if w < 0.5:
423 w = 0.5
424 style = simplestyle.formatStyle({'stroke': '%s' % color, 'fill': 'none', 'stroke-width': '%.1f' % w})
425 if vals[groups['6']]: # Common Linetype
426 if linetypes.has_key(vals[groups['6']][0]):
427 style += ';' + linetypes[vals[groups['6']][0]]
428 entities[entity]()
429 entity = line[1]
430 vals = [[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]]
431 seqs = []
433 doc.write(inkex.sys.stdout)
435 # vim: expandtab shiftwidth=4 tabstop=8 softtabstop=4 encoding=utf-8 textwidth=99