def main(): """ Entry point for readdxf.py. """ args = process_arguments() for f in ut.xpand(args.files): print('Filename: {}'.format(f)) try: data = dx.parse(f) if args.verbose: for d in data: pprint.pprint(d) entities = dx.entities(data) except Exception as ex: logging.info('skipping file {}: {}'.format(f, ex)) continue if not args.all: numbered = dx.numberedlayers(entities) bylayer = {nm: dx.fromlayer(entities, nm) for nm in numbered} entities = [] for layerent in bylayer.values(): entities += layerent num = len(entities) if num == 0: logging.warning('no entities found!') continue print('Contains: {} entities'.format(num)) if args.verbose: for e in entities: pprint.pprint(e) layers = dx.layernames(entities) for layer in layers: print('Layer: "{}"'.format(layer)) for e in dx.fromlayer(entities, layer): printent(e, args.verbose)
def main(): """ Entry point for dxf2nc.py. """ args = process_arguments() sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey} sortkey = sorters[args.sort] lines.epsilon = args.dist for f in utils.xpand(args.files): logging.info('Starting file "{}"'.format(f)) try: ofn = utils.outname(f, extension='.nc') data = dx.parse(f) entities = dx.entities(data) except ValueError as ex: logging.info(str(ex)) fns = "error during processing. Skipping file '{}'." logging.error(fns.format(f)) continue except IOError as ex: logging.info(str(ex)) logging.error("i/o error in file '{}'. Skipping it.".format(f)) continue layers = dx.numberedlayers(entities) entities = [e for e in entities if dx.bycode(e, 8) in layers] num = len(entities) if num == 0: logging.info("no entities found! Skipping file '{}'.".format(f)) continue logging.info('{} entities found.'.format(num)) out = gerbernc.Writer(ofn) for layername in layers: out.newpiece() thislayer = dx.fromlayer(entities, layername) ls = '{} entities found in layer "{}".' logging.info(ls.format(len(thislayer), layername)) segments = lines.mksegments(thislayer) fs = '{} segments in layer "{}"' logging.info(fs.format(len(segments), layername)) if args.contours: cut_contours(segments, out, layername, sortkey) else: segments.sort(key=sortkey) cut_segments(segments, out) out.write()
def main(): """ Entry point for dxfgerber.py. """ args = process_arguments() sorters = {'xy': utils.bbxykey, 'yx': utils.bbyxkey, 'dist': utils.distkey} sortkey = sorters[args.sort] lines.epsilon = args.dist for f in utils.xpand(args.files): logging.info('starting file "{}"'.format(f)) try: ofn = utils.outname(f, extension='.dxf', addenum='_mod') data = dx.parse(f) entities = dx.entities(data) except ValueError as ex: logging.info(str(ex)) fns = "error during processing. Skipping file '{}'." logging.error(fns.format(f)) continue except IOError as ex: logging.info(str(ex)) logging.error("i/o error in file '{}'. Skipping it.".format(f)) continue layers = dx.numberedlayers(entities) entities = [e for e in entities if dx.bycode(e, 8) in layers] num = len(entities) if num == 0: logging.info("no entities found! Skipping file '{}'.".format(f)) continue logging.info('{} entities found.'.format(num)) with open(ofn, 'w') as out: out.write(dxfheader) for layername in layers: thislayer = dx.fromlayer(entities, layername) ls = '{} entities found in layer "{}".' logging.info(ls.format(num, layername)) segments = lines.mksegments(thislayer) fs = '{} segments in layer "{}"' logging.info(fs.format(len(segments), layername)) write_allseg(segments, out, layername, sortkey) out.write(dxffooter)
def main(): """ Entry point for dxf2pdf.py. """ args = process_arguments() for f in utils.xpand(args.files): logging.info('starting file "{}"'.format(f)) try: ofn = utils.outname(f, extension='.pdf', addenum='_dxf') data = dxf.parse(f) entities = dxf.entities(data) except ValueError as ex: logging.info(str(ex)) fns = "cannot construct output filename. Skipping file '{}'." logging.error(fns.format(f)) continue except IOError as ex: logging.info(str(ex)) logging.error("cannot open the file '{}'. Skipping it.".format(f)) continue output(f, ofn, entities, args)
def test_parse(): global data data = dxf.parse('testfiles/demo.dxf') assert len(data) == 4768 assert data[0] == (0, 'SECTION') assert data[-1] == (0, 'EOF')