Improve drawing export and foundation quantity views

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
CopilotandCopilot committed 2026-11-06 15:35:56 +09:00
1 parent a0ec74b09b
commit d22c5008f0
72 files changed
+24346 -12

No files matched your search

+27
View File
@@ -56,6 +56,13 @@ def convert(source,output):
original=ezdxf.readfile(source);audit=original.audit()
if audit.errors:raise ValueError('Input DXF audit failed')
doc=original
# R2000 has no MATERIAL objects. LibreDWG used to turn the default material
# dictionary into invalid ACDBPLACEHOLDER entries that its own reader repairs.
# Remove unsupported metadata before encoding, preserving indexed colours.
materials=[e for e in doc.objects if e.dxftype()=='MATERIAL']
material_dictionary=doc.rootdict.get('ACAD_MATERIAL')
unsupported_handles={e.dxf.handle for e in materials}
if material_dictionary:unsupported_handles.add(material_dictionary.dxf.handle)
# The bundled writer's R2004 path drops entities. R2000 is used after a full round-trip check.
# R2000 uses indexed colours; retain the intended greys with the nearest ACI colour.
colour_count=0
@@ -69,6 +76,25 @@ def convert(source,output):
expected={layout.name:Counter(fingerprint(e) for e in layout) for layout in doc.layouts}
expected_blocks={block.name:Counter(fingerprint(e) for e in block) for block in doc.blocks if not block.name.startswith('*')}
compatibility_angles(intermediate)
# Strip only converter-input metadata after ezdxf has finished serialization;
# ezdxf requires its default materials while saving even an R2000 document.
lines=intermediate.read_text(encoding='cp949').splitlines()
pairs=list(zip(lines[::2],lines[1::2]));groups=[];group=[]
for code,value in pairs:
if code.strip()=='0' and group:groups.append(group);group=[]
group.append((code,value))
if group:groups.append(group)
cleaned=[]
for group in groups:
handle=next((v for c,v in group if c.strip()=='5'),None)
if handle in unsupported_handles:continue
skip=False
for i,(code,value) in enumerate(group):
if skip:skip=False;continue
if code.strip()=='3' and value=='ACAD_MATERIAL':skip=True;continue
if code.strip()=='347':value='0'
cleaned.extend([code,value])
intermediate.write_text('\n'.join(cleaned)+'\n',encoding='cp949')
logs=[]
for args in [[str(TOOLS/'dxf2dwg.exe'),'--as','r2000','-o',str(output),str(intermediate)],
[str(TOOLS/'dwgread.exe'),'-O','DXF','-o',str(output.with_suffix('.roundtrip.dxf')),str(output)]]:
@@ -109,6 +135,7 @@ def convert(source,output):
object_fingerprints_match=True,source_links_match=True,dimension_measurements_match=True,max_dimension_error_mm=max_error,lineweights_match=True,dimstyles_match=True,paper_plot_settings_match=True,font_styles_match=True,audit_errors=len(audit.errors),
decoder_metadata_repairs=[str(e.message) for e in reader_audit.fixes],indexed_colour_conversions=colour_count,
native_autocad_open_tested=False)
report['unsupported_materials_removed']=len(materials)
output.with_suffix('.validation.json').write_text(json.dumps(report,ensure_ascii=False,indent=2),encoding='utf-8')
output.with_suffix('.conversion.log').write_text('\n'.join(logs),encoding='utf-8')
return report