Merge
This commit is contained in:
@@ -68,14 +68,21 @@ def copy_block(src_doc: Drawing, dst_doc: Drawing, blockname: str):
|
||||
|
||||
|
||||
def export_block(src_doc: Drawing, blockname: str, out_dir: str):
|
||||
"""Exportiert einen einzelnen Block als eigene DXF-Datei."""
|
||||
"""Exportiert einen einzelnen Block als eigene DXF-Datei.
|
||||
|
||||
Strategie: Entities des Hauptblocks gehen in den Modelspace der
|
||||
Ausgabedatei (NICHT als named block mit gleichem Name). Dadurch
|
||||
erzeugt vla-InsertBlock in BricsCAD keinen Namenskonflikt /
|
||||
Selbstreferenz-Fehler mehr. Abhaengigkeiten (KS_EIN, KS_AUS, ...)
|
||||
werden weiterhin als Blockdefinitionen in die Blocktabelle kopiert.
|
||||
"""
|
||||
safe_name = blockname.replace("/", "_").replace("\\", "_")
|
||||
out_path = os.path.join(out_dir, safe_name + ".dxf")
|
||||
|
||||
dst_doc = ezdxf.new(dxfversion="R2010")
|
||||
dst_doc.units = src_doc.units
|
||||
|
||||
# Layer aus Quelldatei uebernehmen (nur die benutzten)
|
||||
# Layer aus Quelldatei uebernehmen
|
||||
for layer in src_doc.layers:
|
||||
if layer.dxf.name not in dst_doc.layers:
|
||||
try:
|
||||
@@ -86,8 +93,30 @@ def export_block(src_doc: Drawing, blockname: str, out_dir: str):
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Block + Abhaengigkeiten kopieren
|
||||
copy_block(src_doc, dst_doc, blockname)
|
||||
# Nur Abhaengigkeiten (nicht den Hauptblock selbst) als named blocks kopieren
|
||||
deps = collect_dependencies(src_doc, blockname, set())
|
||||
deps.discard(blockname)
|
||||
for dep in deps:
|
||||
if dep not in src_doc.blocks or dep in dst_doc.blocks:
|
||||
continue
|
||||
src_blk = src_doc.blocks[dep]
|
||||
dst_blk = dst_doc.blocks.new(
|
||||
name=dep,
|
||||
base_point=src_blk.block.dxf.base_point if hasattr(src_blk.block.dxf, "base_point") else (0, 0, 0),
|
||||
)
|
||||
for entity in src_blk:
|
||||
try:
|
||||
dst_blk.add_entity(entity.copy())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
# Hauptblock-Entities direkt in den Modelspace schreiben (sichtbar + kein Namenskonflikt)
|
||||
msp = dst_doc.modelspace()
|
||||
for entity in src_doc.blocks[blockname]:
|
||||
try:
|
||||
msp.add_entity(entity.copy())
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
dst_doc.saveas(out_path)
|
||||
return out_path
|
||||
@@ -126,10 +155,10 @@ def main():
|
||||
has_ks_aus = "KS_AUS" in check_doc.blocks
|
||||
ks_status = ""
|
||||
if name not in ALWAYS_INCLUDE:
|
||||
blk = check_doc.blocks[name]
|
||||
inserts = [e.dxf.name for e in blk if e.dxftype() == "INSERT"]
|
||||
has_ks_ein_ref = "KS_EIN" in inserts
|
||||
has_ks_aus_ref = "KS_AUS" in inserts
|
||||
# Hauptblock liegt jetzt im Modelspace, nicht mehr als named block
|
||||
msp_inserts = [e.dxf.name for e in check_doc.modelspace() if e.dxftype() == "INSERT"]
|
||||
has_ks_ein_ref = "KS_EIN" in msp_inserts
|
||||
has_ks_aus_ref = "KS_AUS" in msp_inserts
|
||||
ks_status = f" KS_EIN={'ja' if has_ks_ein_ref else 'NEIN'} KS_AUS={'ja' if has_ks_aus_ref else 'NEIN'}"
|
||||
print(f" OK {name}{ks_status}")
|
||||
ok += 1
|
||||
|
||||
Reference in New Issue
Block a user