fix: detect Revit floor frames deterministically
This commit is contained in:
@@ -148,6 +148,77 @@ def make_multiframe_dxf(path: Path, mif_titles: bool = False) -> None:
|
||||
doc.saveas(path)
|
||||
|
||||
|
||||
def make_revit_named_frames_dxf(path: Path) -> None:
|
||||
"""Two side-by-side plans whose floor identity exists only in INSERT names.
|
||||
|
||||
Mirrors Revit exports where visible titles are decoration-coded text on
|
||||
G-ANNO-TTLB at paper coordinates, while door/window family block names end
|
||||
in ``-首层平面图`` or ``-二层平面图`` at the real model coordinates.
|
||||
"""
|
||||
doc = ezdxf.new("R2010", setup=True)
|
||||
for layer in ("I-WALL", "S-GRID", "A-DOOR", "G-ANNO-TTLB"):
|
||||
doc.layers.add(layer)
|
||||
msp = doc.modelspace()
|
||||
|
||||
for title, ox in (("首层平面图", 0.0), ("二层平面图", 70000.0)):
|
||||
outline = [((0, 0), (40000, 0)), ((40000, 0), (40000, 20000)),
|
||||
((40000, 20000), (0, 20000)), ((0, 20000), (0, 0))]
|
||||
interior = [((4000 * i, 0), (4000 * i, 20000)) for i in range(1, 10)]
|
||||
for (sx, sy), (ex, ey) in outline + interior:
|
||||
msp.add_line((sx + ox, sy), (ex + ox, ey), dxfattribs={"layer": "I-WALL"})
|
||||
for y in (0, 7000, 13000, 20000):
|
||||
msp.add_line((ox - 2000, y), (ox + 42000, y), dxfattribs={"layer": "S-GRID"})
|
||||
|
||||
block_name = f"门族-001-{title}"
|
||||
door = doc.blocks.new(name=block_name)
|
||||
door.add_line((0, 0), (900, 0), dxfattribs={"layer": "A-DOOR"})
|
||||
# Distributed INSERT positions are robust frame seeds; include the
|
||||
# extrema so the proposed clip covers the complete wall outline.
|
||||
for i in range(12):
|
||||
x = ox + (40000 * i / 11)
|
||||
y = 20000 * (i % 4) / 3
|
||||
msp.add_blockref(block_name, (x, y))
|
||||
|
||||
# This text must not become a third frame or leak the AutoCAD underline
|
||||
# control code into keys such as ``_L_``.
|
||||
msp.add_text(r"\L主楼首层_二层平面图", height=800,
|
||||
dxfattribs={"layer": "G-ANNO-TTLB"}).set_placement((0, 80000))
|
||||
doc.saveas(path)
|
||||
|
||||
|
||||
def make_revit_overlapping_roof_dxf(path: Path) -> None:
|
||||
"""Roof and machine-room-roof labels vote for the same geometry frame."""
|
||||
doc = ezdxf.new("R2010", setup=True)
|
||||
for layer in ("I-WALL", "S-GRID", "A-DOOR"):
|
||||
doc.layers.add(layer)
|
||||
msp = doc.modelspace()
|
||||
for i in range(12):
|
||||
x = 4000.0 * i
|
||||
msp.add_line((x, 0), (x, 24000), dxfattribs={"layer": "I-WALL"})
|
||||
for y in (0, 8000, 16000, 24000):
|
||||
msp.add_line((0, y), (44000, y), dxfattribs={"layer": "S-GRID"})
|
||||
for title in ("屋面平面图", "机房小屋面"):
|
||||
block = doc.blocks.new(name=f"屋面构件-{title}")
|
||||
block.add_line((0, 0), (900, 0), dxfattribs={"layer": "A-DOOR"})
|
||||
for i in range(12):
|
||||
msp.add_blockref(block.name, (4000.0 * i, 2000.0 * (i % 10)))
|
||||
doc.saveas(path)
|
||||
|
||||
|
||||
def make_same_floor_two_buildings_dxf(path: Path) -> None:
|
||||
"""Two building-qualified F1 plans must not collapse into one frame."""
|
||||
doc = ezdxf.new("R2010", setup=True)
|
||||
for layer in ("WALL", "A-TEXT"):
|
||||
doc.layers.add(layer)
|
||||
msp = doc.modelspace()
|
||||
for title, ox in (("1#楼一层平面图", 0.0), ("2#楼一层平面图", 70000.0)):
|
||||
msp.add_text(title, height=800, dxfattribs={"layer": "A-TEXT"}).set_placement((ox, 25000))
|
||||
for i in range(16):
|
||||
msp.add_line((ox + 2000 * i, 0), (ox + 2000 * i, 20000),
|
||||
dxfattribs={"layer": "WALL"})
|
||||
doc.saveas(path)
|
||||
|
||||
|
||||
def make_blockgrid_dxf(path: Path) -> None:
|
||||
"""黄桥 pattern: plan grids live inside anonymous wrapper blocks (A$C...),
|
||||
NOT in modelspace, and floor wall bboxes differ (F2 covers half the
|
||||
@@ -600,6 +671,64 @@ def main() -> int:
|
||||
ok_offset = abs(off["F2"][0] - 0.0) <= 120 and abs(off["F2"][1] - 98100.0) <= 120
|
||||
check("grid alignment recovers frame offset", ok_offset, str(off))
|
||||
|
||||
# --- Revit export: title block lies, INSERT-name floor evidence wins ---
|
||||
revit_dir = WORK / "dxf_revit_named"
|
||||
revit_dir.mkdir(parents=True, exist_ok=True)
|
||||
revit_path = revit_dir / "A208 - 主楼首层、二层平面图.dxf"
|
||||
make_revit_named_frames_dxf(revit_path)
|
||||
proc = run([
|
||||
sys.executable, "scripts/cad_dxf_report.py",
|
||||
"--input", str(revit_dir), "--work", str(WORK / "report_work_revit"),
|
||||
"--output", str(WORK / "read_report_revit"), "--vendor-dir", str(VENDOR),
|
||||
])
|
||||
check("Revit INSERT-name report runs", proc.returncode == 0, proc.stderr[-600:])
|
||||
revit_report = json.loads((WORK / "read_report_revit" / "cad_read_report.json").read_text(encoding="utf-8"))
|
||||
revit_item = revit_report["files"][0]
|
||||
check("Revit floor count ignores TTLB duplicate", revit_item.get("plan_title_count") == 2, str(revit_item))
|
||||
check("Revit two-floor sheet raises multi-frame warning",
|
||||
any("multi_frame_sheet" in w for w in revit_item.get("warnings", [])), str(revit_item.get("warnings")))
|
||||
|
||||
proc = run([
|
||||
sys.executable, "scripts/detect_sheet_frames.py",
|
||||
"--dxf", str(revit_path), "--out-config", str(WORK / "frames_revit.json"),
|
||||
"--out-report", str(WORK / "frames_revit.md"), "--vendor-dir", str(VENDOR),
|
||||
])
|
||||
check("detect uses Revit INSERT-name evidence", proc.returncode == 0, proc.stderr[-600:])
|
||||
if proc.returncode == 0:
|
||||
revit_frames = json.loads((WORK / "frames_revit.json").read_text(encoding="utf-8"))
|
||||
revit_floors = revit_frames["drawings"][0]["floors"]
|
||||
revit_keys = sorted(f["key"] for f in revit_floors)
|
||||
check("Revit title formatting yields F1/F2 only", revit_keys == ["F1", "F2"], str(revit_keys))
|
||||
revit_clips = {f["key"]: f["clip"] for f in revit_floors}
|
||||
separated = (revit_clips.get("F1", [0, 0, 0, 0])[2]
|
||||
< revit_clips.get("F2", [0, 0, 0, 0])[0])
|
||||
check("Revit INSERT-name clips stay spatially separated", separated, str(revit_clips))
|
||||
|
||||
roof_path = revit_dir / "A212 - 主楼屋顶平面图.dxf"
|
||||
make_revit_overlapping_roof_dxf(roof_path)
|
||||
proc = run([
|
||||
sys.executable, "scripts/detect_sheet_frames.py",
|
||||
"--dxf", str(roof_path), "--out-config", str(WORK / "frames_revit_roof.json"),
|
||||
"--out-report", str(WORK / "frames_revit_roof.md"), "--vendor-dir", str(VENDOR),
|
||||
])
|
||||
check("detect handles overlapping Revit roof identities", proc.returncode == 0, proc.stderr[-600:])
|
||||
roof_report = (WORK / "frames_revit_roof.md").read_text(encoding="utf-8")
|
||||
check("overlapping roof frames demand Agent resolution",
|
||||
"AMBIGUOUS overlapping inferred frames" in roof_report, roof_report[-800:])
|
||||
|
||||
twin_path = revit_dir / "same-floor-two-buildings.dxf"
|
||||
make_same_floor_two_buildings_dxf(twin_path)
|
||||
proc = run([
|
||||
sys.executable, "scripts/cad_dxf_report.py",
|
||||
"--input", str(revit_dir), "--work", str(WORK / "report_work_revit_twin"),
|
||||
"--output", str(WORK / "read_report_revit_twin"), "--vendor-dir", str(VENDOR),
|
||||
])
|
||||
check("same-floor two-building report runs", proc.returncode == 0, proc.stderr[-600:])
|
||||
twin_report = json.loads((WORK / "read_report_revit_twin" / "cad_read_report.json").read_text(encoding="utf-8"))
|
||||
twin_item = next(item for item in twin_report["files"] if item["file"] == twin_path.name)
|
||||
check("same floor in two qualified buildings counts as two frames",
|
||||
twin_item.get("plan_title_count") == 2, str(twin_item))
|
||||
|
||||
frames.update({"scale": 0.001, "layers": {"walls": ["WALL"], "grid": ["DOTE"]}})
|
||||
aligned_cfg = WORK / "config_frames.json"
|
||||
aligned_cfg.write_text(json.dumps(frames, ensure_ascii=False), encoding="utf-8")
|
||||
|
||||
Reference in New Issue
Block a user