First corrections: dxf_import.zip (red Arrows instead of small circles). dxf_input.py, dxf_input.inx.
After looking into dxf_import.py: inside export_LWPOLYLINE, got bulge=2.414214. It passes over next 42 section: 2.999999 and seqs="['8', '62', '370', '6', '70', '10', '20', '42', '10', '20', '42', '2']"
AcDbPolyline 90 2 70 1 10 0.0000000000000002 20 -0.0000000000000004 42 2.4142135623730949 10 2.9999999999999996 20 -3.0 42 0.414213562373095 0 ENDSEC
for i in range (1, len(vals[groups['10']])):
bulge = 0
iseqs += 1
while seqs[iseqs] != '20':
if seqs[iseqs] == '42':
bulge = vals[groups['42']][ibulge]
ibulge += 1
iseqs += 1
if bulge:
print_("got bulge=%f" % bulge)
sweep = 0 # sweep CCW
if bulge < 0:
sweep = 1 # sweep CW
bulge = -bulge
large = 0 # large-arc-flag
if bulge > 1:
large = 1
r = math.sqrt((vals[groups['10']][i] - xold)**2 + (vals[groups['20']][i] - yold)**2)
r = 0.25*r*(bulge + 1.0/bulge)
path += ' A %f,%f 0.0 %d %d %f,%f' % (r, r, large, sweep, vals[groups['10']][i], vals[groups['20']][i])
else:
path += ' L %f,%f' % (vals[groups['10']][i], vals[groups['20']][i])
xold = vals[groups['10']][i]
yold = vals[groups['20']][i]
Modified code
def export_LWPOLYLINE():
print_("inside export_LWPOLYLINE")
# mandatory group codes : (10, 20, 70) (x, y, flags)
if vals[groups['10']] and vals[groups['20']] and vals[groups['70']]:
if len(vals[groups['10']]) > 1 and len(vals[groups['20']]) == len(vals[groups['10']]):
# optional group codes : (42) (bulge)
iseqs = 0
ibulge = 0
while seqs[iseqs] != '20':
iseqs += 1
path = 'M %f,%f' % (vals[groups['10']][0], vals[groups['20']][0])
print_("first iseqs=%i" % iseqs)
xold = vals[groups['10']][0]
yold = vals[groups['20']][0]
print_(seqs)
print_(vals[groups['10']])
print_(vals[groups['20']])
print_(vals[groups['42']])
for i in range (0,2):
print_("hello i=%i" % i)
for i in range (0, len(vals[groups['10']])):
print_("got i=%i, range=%f" % (i,len(vals[groups['10']])))
bulge = 0
iseqs += 1
while seqs[iseqs] != '20' and seqs[iseqs] != '2': # cycle to the next 20 (y) occurance. looking up for bulge
print_("got iseqs=%f, seqs[iseqs]=%s" % (iseqs,seqs[iseqs]))
if seqs[iseqs] == '42':
bulge = vals[groups['42']][ibulge]
ibulge += 1
iseqs += 1
if bulge:
print_("got bulge=%f" % bulge)
sweep = 0 # sweep CCW
if bulge < 0:
sweep = 1 # sweep CW
bulge = -bulge
large = 0 # large-arc-flag
if bulge > 1:
large = 1
r = math.sqrt((vals[groups['10']][i] - xold)**2 + (vals[groups['20']][i] - yold)**2)
r = 0.25*r*(bulge + 1.0/bulge)
path += ' A %f,%f 0.0 %d %d %f,%f' % (r, r, large, sweep, vals[groups['10']][i], vals[groups['20']][i])
else:
path += ' L %f,%f' % (vals[groups['10']][i], vals[groups['20']][i])
xold = vals[groups['10']][i]
yold = vals[groups['20']][i]
if vals[groups['70']][0] == 1: # closed path
path += ' z'
attribs = {'d': path, 'style': style}
inkex.etree.SubElement(layer, 'path', attribs)
and it's output:
inside export_LWPOLYLINE
first iseqs=6
['8', '62', '370', '6', '70', '10', '20', '42', '10', '20', '42', '2']
[7.0866141732283466e-016, 10.629921259842519]
[1052.3622047244096, 1062.992125984252]
[2.4142135623730949, 0.41421356237309498]
hello i=0
hello i=1
got i=0, range=2.000000
got iseqs=7.000000, seqs[iseqs]=42
got iseqs=8.000000, seqs[iseqs]=10
got bulge=2.414214
got i=1, range=2.000000
got iseqs=10.000000, seqs[iseqs]=42
got bulge=0.414214
path="M 0.000000,1052.362205
A 0.000000,0.000000 0.0 1 0 0.000000,1052.362205
A 10.629921,10.629921 0.0 0 0 10.629921,1062.992126 z"
Used test dot0_0.dxf - one point and one circle
Original AutoCAD DXF specification. Chapter LWPOLYLINE:
Lwpolyline group codes
Group codeDescription
100 Subclass marker (AcDbPolyline)
90 Number of vertices
70 Polyline flag (bit-coded); default is 0:
1 = Closed; 128 = Plinegen
43 Constant width (optional; default = 0). Not used if variable width
(codes 40 and/or 41) is set
38 Elevation (optional; default = 0)
39 Thickness (optional; default = 0)
10 Vertex coordinates (in OCS), multiple entries; one entry for each vertex
DXF: X value; APP: 2D point
20 DXF: Y value of vertex coordinates (in OCS), multiple entries; one entry
for each vertex
40 Starting width (multiple entries; one entry for each vertex) (optional;
default = 0; multiple entries). Not used if constant width
(code 43) is set
41 End width (multiple entries; one entry for each vertex) (optional;
default = 0; multiple entries). Not used if constant width
(code 43) is set
42 Bulge (multiple entries; one entry for each vertex) (optional; default=0)