diff --git a/scripts/detect_sheet_frames.py b/scripts/detect_sheet_frames.py index b3202f7..85db493 100644 --- a/scripts/detect_sheet_frames.py +++ b/scripts/detect_sheet_frames.py @@ -274,7 +274,13 @@ def main() -> int: x, y = float(pos.x), float(pos.y) except Exception: continue - height = float(entity.dxf.get("height", 0) or 0) + # MTEXT stores char_height; asking MTEXT for "height" raises + # DXFAttributeError (only undefined-for-type attributes raise). + try: + height_attr = "char_height" if kind == "MTEXT" else "height" + height = float(entity.dxf.get(height_attr, 0) or 0) + except Exception: + height = 0.0 layer = str(entity.dxf.layer) if plan_title.search(content) and not (plan_exclude and plan_exclude.search(content)): if not match_any(layer, title_excludes): diff --git a/tests/test_extraction_pipeline.py b/tests/test_extraction_pipeline.py index 21cfe1b..dc4359a 100644 --- a/tests/test_extraction_pipeline.py +++ b/tests/test_extraction_pipeline.py @@ -141,6 +141,9 @@ def make_multiframe_dxf(path: Path, mif_titles: bool = False) -> None: draw_frame(0.0, "一层平面图") draw_frame(-pitch, "二层平面图") + # a SHORT MTEXT reaches the title-height probe (long ones are skipped + # first); MTEXT has char_height, not height — 27号 1#A crashed here + msp.add_mtext("备注说明", dxfattribs={"layer": "PUB_TEXT", "char_height": 500}).set_location((5000, 5000)) doc.saveas(path)