本文整理匯總了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')
示例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_())
示例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()}')
示例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
示例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))
示例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'
示例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)
示例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")
示例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")
示例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")
示例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')
示例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}")
示例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))
示例14: load_3D_model
# 需要導入模塊: import ezdxf [as 別名]
# 或者: from ezdxf import readfile [as 別名]
def load_3D_model():
import ezdxf
ezdxf.readfile(filename=_3D_MODEL)
示例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