当前位置: 首页>>代码示例>>Python>>正文


Python ezdxf.readfile方法代码示例

本文整理汇总了Python中ezdxf.readfile方法的典型用法代码示例。如果您正苦于以下问题:Python ezdxf.readfile方法的具体用法?Python ezdxf.readfile怎么用?Python ezdxf.readfile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ezdxf的用法示例。


在下文中一共展示了ezdxf.readfile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: optimize

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def optimize(name: str):
    filename = SRCDIR / name
    new_filename = OUTDIR / ('optimized_' + name)
    print(f'opening DXF file: {filename}')
    start_time = time.time()
    doc = ezdxf.readfile(filename)
    msp = doc.modelspace()
    end_time = time.time()
    print(f'time for reading: {end_time - start_time:.1f} seconds')
    print(f"DXF version: {doc.dxfversion}")
    print(f"Database contains {len(doc.entitydb)} entities.")
    polyfaces = (polyline for polyline in msp.query('POLYLINE') if polyline.is_poly_face_mesh)
    optimize_polyfaces(polyfaces)

    print(f'saving DXF file: {new_filename}')
    start_time = time.time()
    doc.saveas(new_filename)
    end_time = time.time()
    print(f'time for saving: {end_time - start_time:.1f} seconds') 
开发者ID:mozman,项目名称:ezdxf,代码行数:21,代码来源:optimize_polyfaces.py

示例2: _main

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def _main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--cad_file')
    parser.add_argument('--layout', default='Model')
    args = parser.parse_args()

    signal.signal(signal.SIGINT, signal.SIG_DFL)  # handle Ctrl+C properly
    app = qw.QApplication(sys.argv)

    v = CadViewer()
    if args.cad_file is not None:
        v.set_document(ezdxf.readfile(args.cad_file))
        try:
            v.draw_layout(args.layout)
        except KeyError:
            print(f'could not find layout "{args.layout}". Valid layouts: {[l.name for l in v.doc.layouts]}')
            sys.exit(1)
    sys.exit(app.exec_()) 
开发者ID:mozman,项目名称:ezdxf,代码行数:20,代码来源:cad_viewer.py

示例3: main

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def main():
    doc = ezdxf.readfile(DIR / 'crash_test_1.dxf')
    print(ezdxf.version)
    model_space = doc.modelspace()
    for entity in model_space:
        print(entity.dxftype())
        if entity.dxftype() == 'INSERT':
            entity = cast(Insert, entity)
            d = entity.dxf
            block_name = d.name
            print(f'Insert entity at {entity.dxf.insert} with scaling {entity.has_scaling} ({entity.has_uniform_scaling})')
            print(f'scaling = {d.xscale}, {d.yscale}, {d.zscale}')
            print(f'block = {block_name}')

            print('\nentities from block:')
            block = doc.blocks[block_name]
            for child in block:
                print(f'child: {child.dxftype()}')
                for key, value in child.dxf.all_existing_dxf_attribs().items():
                    print(f' - {key}: {value}')

            print('\nvirtual entities:')
            entities = entity.virtual_entities()
            for child in entities:
                print(f'child: {child.dxftype()}') 
开发者ID:mozman,项目名称:ezdxf,代码行数:27,代码来源:issue140.py

示例4: test_open_proe_ac1018

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def test_open_proe_ac1018():
    doc = ezdxf.readfile(FILE)
    modelspace = doc.modelspace()

    # are there entities in model space
    assert 17 == len(modelspace)

    # can you get entities
    lines = modelspace.query('LINE')
    assert 12 == len(lines)

    # is owner tag correct
    first_line = lines[0]
    assert modelspace.layout_key == first_line.dxf.owner

    # is paper space == 0
    assert 0 == first_line.dxf.paperspace 
开发者ID:mozman,项目名称:ezdxf,代码行数:19,代码来源:test_423_read_proe_r2004.py

示例5: has_dxf_entity

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def has_dxf_entity(filename, entity_name):
    try:
        dwg = ezdxf.readfile(filename, legacy_mode=True)
    except IOError:
        return False
    except ezdxf.DXFError as e:
        print('\n' + '*' * 40)
        print('FOUND DXF ERROR: {}'.format(str(e)))
        print('*' * 40 + '\n')
        return False
    else:
        entities = dwg.modelspace().query(entity_name)
        if len(entities):
            return True
        if 'objects' in dwg.sections:
            entities = dwg.objects.query(entity_name)
        return bool(len(entities)) 
开发者ID:mozman,项目名称:ezdxf,代码行数:19,代码来源:search_entity.py

示例6: test_write_R12_without_handles

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def test_write_R12_without_handles(filename, tmpdir):
    dwg = ezdxf.readfile(filename)
    dwg.header['$HANDLING'] = 0
    export_path = str(tmpdir.join("dxf_r12_without_handles.dxf"))
    dwg.saveas(export_path)

    # can't check with ezdxf.readfile(), because handles automatically enabled
    with open(export_path) as f:
        tagger = ascii_tags_loader(f)
        sections = load_dxf_structure(tagger)
        for entity in sections['ENTITIES']:
            with pytest.raises(ezdxf.DXFValueError):  # has no handles
                entity.get_handle()

        for entity in sections['TABLES']:
            if entity[0] != (0, 'DIMSTYLE'):
                with pytest.raises(ezdxf.DXFValueError):  # has no handles
                    entity.get_handle()
            else:  # special DIMSTYLE entity
                assert len(entity.find_all(105)) == 0, 'remove handle group code 105'
                assert len(entity.find_all(5)) == 1, 'do not remove group code 5' 
开发者ID:mozman,项目名称:ezdxf,代码行数:23,代码来源:test_write_without_handles.py

示例7: test_entities_iterator

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def test_entities_iterator(dxfversion, tmpdir):
    filename = tmpdir.join('polyline_{}.dxf'.format(dxfversion))
    #  filename = r'C:\Users\manfred\Desktop\Now\polyline_{}.dxf'.format(dxfversion)
    filename = str(filename)
    drawing = ezdxf.new(dxfversion)
    modelspace = drawing.modelspace()
    modelspace.add_polyline3d(POINTS)
    drawing.saveas(filename)

    assert os.path.exists(filename)

    dxf = ezdxf.readfile(filename)
    for entity in dxf.entities:
        if entity.dxftype() == 'POLYLINE':  # iterator ok
            points = list(entity.points())
            assert len(points) == len(POINTS) 
开发者ID:mozman,项目名称:ezdxf,代码行数:18,代码来源:test_entities_iterator.py

示例8: calc

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def calc(dxffile):
    def group_key(entity):  # group entities by (dxftype, layer)
        return entity.dxftype(), entity.dxf.layer

    doc = ezdxf.readfile(dxffile)
    msp = doc.modelspace()
    groups = msp.groupby(key=group_key)
    # using get(): returns None if key does not exist
    columns = groups.get(('CIRCLE', 'AR_ME_ST'))  # all CIRCLE entities on layer 'AR_ME_ST'
    outer_walls = groups.get(('LINE', 'AR_ME_AW'))  # all LINE entities on layer 'AR_ME_AW'
    inner_walls = groups.get(('LINE', 'AR_ME_IW'))  # all LINE entities on layer 'AR_ME_IW'
    beams = groups.get(('LINE', 'AR_ME_TR'))  # all LINE entities on layer 'AR_ME_TR'

    with open(outname(dxffile), 'wt', encoding='utf-8') as f:
        f.write("File: {}\n".format(dxffile))
        if columns is not None:
            f.write(f"Stützen Anzahl={len(columns)}\n")
        if outer_walls is not None:
            f.write(f"Aussenwände Anzahl={len(outer_walls)}\n")
            f.write(f"Aussenwände Gesamtlänge={length(outer_walls)}\n")
        if inner_walls is not None:
            f.write(f"Innenwände Anzahl={len(inner_walls)}\n")
            f.write(f"Innenwände Gesamtlänge={length(inner_walls)}\n")
        if beams is not None:
            f.write(f"Träger Anzahl={len(beams)}\n")
            f.write(f"Träger Gesamtlänge={length(beams)}\n") 
开发者ID:mozman,项目名称:ezdxf,代码行数:28,代码来源:using_groupby.py

示例9: clone_spline

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def clone_spline():
    doc = readfile("Spline_R2000_fit_spline.dxf")
    msp = doc.modelspace()
    spline = cast(Spline, msp.query('SPLINE').first)
    # delete the existing spline from model space and drawing database
    msp.delete_entity(spline)
    # add a new spline
    msp.add_spline(spline.fit_points)
    doc.saveas("Spline_R2000_clone_Spline.dxf") 
开发者ID:mozman,项目名称:ezdxf,代码行数:11,代码来源:spline.py

示例10: add_points_to_spline

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def add_points_to_spline():
    doc = readfile("Spline_R2000_fit_spline.dxf")
    msp = doc.modelspace()
    spline = cast(Spline, msp.query('SPLINE').first)

    spline.fit_points.append((3130, 610, 0))
    # As far I tested this works without complaints from AutoCAD, but for the case of problems
    spline.control_points = []  # delete control points, this could modify the geometry of the spline
    spline.knots = []  # delete knot values, this shouldn't modify the geometry of the spline
    spline.weights = []  # delete weights, this could modify the geometry of the spline

    doc.saveas("Spline_R2000_with_added_points.dxf") 
开发者ID:mozman,项目名称:ezdxf,代码行数:14,代码来源:spline.py

示例11: copydxf

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def copydxf(fromfile, tofile):
    starttime = time.time()
    doc = ezdxf.readfile(fromfile)
    doc.saveas(tofile)
    endtime = time.time()
    print(f'copy time: {endtime - starttime:.2f} seconds') 
开发者ID:mozman,项目名称:ezdxf,代码行数:8,代码来源:copydxf.py

示例12: process_file

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def process_file(filename):
    doc = ezdxf.readfile(filename)
    if doc.dxfversion > 'AC1009':
        print_layouts(doc.layouts)
    else:
        print(f"DXF R12 not supported: {filename}") 
开发者ID:mozman,项目名称:ezdxf,代码行数:8,代码来源:print_layout_properties.py

示例13: _select_doc

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def _select_doc(self):
        path, _ = qw.QFileDialog.getOpenFileName(self, caption='Select CAD Document', filter='DXF Documents (*.dxf)')
        if path:
            self.set_document(ezdxf.readfile(path)) 
开发者ID:mozman,项目名称:ezdxf,代码行数:6,代码来源:cad_viewer.py

示例14: load_3D_model

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def load_3D_model():
    import ezdxf
    ezdxf.readfile(filename=_3D_MODEL) 
开发者ID:mozman,项目名称:ezdxf,代码行数:5,代码来源:read_big_R12_files.py

示例15: iter_3D_model

# 需要导入模块: import ezdxf [as 别名]
# 或者: from ezdxf import readfile [as 别名]
def iter_3D_model():
    import ezdxf
    doc = ezdxf.readfile(filename=_3D_MODEL)
    msp = doc.modelspace()
    count = 0
    for e in msp:
        e.dxftype()
        count += 1
    print(f'Iterated {count} entities in modelspace (fanuc-430-arm.dxf).')
    del doc 
开发者ID:mozman,项目名称:ezdxf,代码行数:12,代码来源:read_big_R12_files.py


注:本文中的ezdxf.readfile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。