From e0cd974c6b78dea2702b0c1fb66f5a641fe03005 Mon Sep 17 00:00:00 2001 From: zhengwr Date: Tue, 21 Jul 2026 14:38:30 +0800 Subject: [PATCH] fix: distinguish Revit view wrappers from family blocks --- scripts/detect_sheet_frames.py | 7 ++++++- tests/test_extraction_pipeline.py | 26 ++++++++++++++++---------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/scripts/detect_sheet_frames.py b/scripts/detect_sheet_frames.py index 0422eec..42a894b 100644 --- a/scripts/detect_sheet_frames.py +++ b/scripts/detect_sheet_frames.py @@ -718,7 +718,12 @@ def main() -> int: "layer": "INSERT_NAME", "_clip_hint": clip_hint, "_preserve_component_union": key in preserve_component_union_keys, - "_include_block_names": [f"*-{label}"], + # Only a small number of large top-level view wrappers can be + # used as root INSERT selectors. Repeated family/component + # blocks also end in the view name in many Revit exports; using + # their suffix as a root filter drops unrelated wall/column + # INSERTs from the same floor. + **({"_include_block_names": [f"*-{label}"]} if 1 <= len(points) <= 3 and len(expanded) >= 50 else {}), } ) diff --git a/tests/test_extraction_pipeline.py b/tests/test_extraction_pipeline.py index 7abf6d1..8064804 100644 --- a/tests/test_extraction_pipeline.py +++ b/tests/test_extraction_pipeline.py @@ -210,16 +210,17 @@ def make_revit_overlapping_roof_dxf(path: Path) -> None: 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))) + for index, title in enumerate(("屋面平面图", "机房小屋面"), start=1): + # True view wrapper: one large root INSERT carries the whole plan. This + # is intentionally different from repeated family blocks whose names + # also end in a floor title. + block = doc.blocks.new(name=f"NY-ARCH_rvt-{index}-{title}") + for i in range(55): + x = 800.0 * i + block.add_line((x, 0), (x, 24000), dxfattribs={"layer": "I-WALL"}) + for y in (0, 4000, 8000, 12000, 16000, 20000, 24000): + block.add_line((0, y), (43200, y), dxfattribs={"layer": "S-GRID"}) + msp.add_blockref(block.name, (0, 0)) doc.saveas(path) @@ -870,6 +871,11 @@ def main() -> int: 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)) + check( + "repeated Revit family suffixes do not become root selectors", + all("include_block_names" not in floor for floor in revit_floors), + str(revit_floors), + ) roof_path = revit_dir / "A212 - 主楼屋顶平面图.dxf" make_revit_overlapping_roof_dxf(roof_path)