def main(filein, fileout, width, height, gap): d = dxfgrabber.read(filein) def flipxy(p): return (p[1], p[0]) layers = {} for r in d.entities: if not r.layer in layers: layers[r.layer] = [] layers[r.layer].append(map(flipxy, r.points)) polys_to_cut = [] for (_, ps) in layers.iteritems(): polys_to_cut += map(lambda p: geo.extend_poly(gap, p, False), ps) h = height / 2.0 w = width / 2.0 gndplane = Polygon([(h, w), (-h, w), (-h, -w), (h, -w)]) for p in polys_to_cut: gndplane = gndplane - Polygon(p) # Polygon.triStrip() returns a list of tristrips which need to be # turned into quads, and the list needs to be flattened. layers["GROUND"] = [ quad for quads in map( geo.tristrip_to_quads, gndplane.triStrip()) for quad in quads] drawing = DXFEngine.drawing(fileout) for (l, qs) in layers.iteritems(): for q in qs: drawing.add(DXFEngine.face3d(map(flipxy, q), layer=l)) drawing.save()