"""'형상 일람(모델)' 시트의 옥성 도면↔모델 대조 이미지 2장(제목 '옥성 코핑 — 도면' / '옥성 기초 — 도면')을 원본 DXF 렌더 기준 새 이미지로 교체. 하루 1백업.""" import hashlib, shutil from pathlib import Path import openpyxl from openpyxl.drawing.image import Image as XLImage from xlsx_backup_once import backup_once, NAME ROOT = Path(r"D:\★Pier 자료\프로그램\Pier_T"); REV = ROOT / "검토파일"; ORIG = Path(r"D:\★Pier 자료\심수석님 검토 파일"); CAP = REV / "수정후_캡처" print("backup:", backup_once()) wb = openpyxl.load_workbook(REV / NAME); sh = wb["형상 일람(모델)"] targets = {"옥성 코핑 — 도면": "도면대조_옥성_코핑.png", "옥성 기초 — 도면": "도면대조_옥성_기초.png"} done = 0 for i, old in enumerate(sh._images): r = old.anchor._from.row; title = str(sh.cell(row=r, column=1).value or "") for key, f in targets.items(): if title.startswith(key): n = XLImage(str(CAP / f)); w = old.width; n.height = int(w * n.height / n.width); n.width = w n.anchor = old.anchor; sh._images[i] = n; sh.cell(row=r, column=1, value=title.split(" 대조")[0] + " 대조 (원본 DXF 렌더)"); done += 1 print("replaced", done) wb.save(REV / NAME); shutil.copy2(REV / NAME, ORIG / NAME) sha = lambda p: hashlib.sha256(Path(p).read_bytes()).hexdigest() print("sha equal:", sha(REV / NAME) == sha(ORIG / NAME), sha(REV / NAME)[:16], len(sh._images))