#! python3 # make layer visibility of each modified model equal to its reviewed (검토완료) model, so rebar is visible on open # a file locked by another Rhino window is skipped and reported (not overwritten) import os, json, traceback import Rhino BASE = r"D:\★Pier 자료\프로그램\Pier_T\검토파일" PAIRS = [ ("철근 모델랑 운곡교P1_바이브코딩", "운곡교p1_검토완료.3dm", "운곡교p1_수정2_20261023.3dm"), ("검토_산외교P1", "산외교P1 G5_검토완료.3dm", "산외교P1 G5_수정_20261023.3dm"), ("검토_옥성교P1", "옥성교P1_G5_검토완료.3dm", "옥성교P1_G5_수정_20261023.3dm"), ("Ramp-A교P1", "ramp-A G5_검토완료.3dm", "ramp-A G5_수정_20261023.3dm"), ] OUT = r"C:\Users\User\AppData\Local\PierApp\jobs\c1_work\c1_layers_on.json" res = {} def fix_one(folder, rev, mod): rdoc = Rhino.RhinoDoc.OpenHeadless(os.path.join(BASE, folder, rev)) want = {l.FullPath: l.IsVisible for l in rdoc.Layers} rdoc.Dispose() p = os.path.join(BASE, folder, mod) doc = Rhino.RhinoDoc.OpenHeadless(p) changed = [] for l in list(doc.Layers): if l.IsDeleted: continue if want.get(l.FullPath) and not l.IsVisible: doc.Layers.ForceLayerVisible(l.Index) changed.append(l.FullPath) still_off = [l.FullPath for l in doc.Layers if (not l.IsDeleted) and want.get(l.FullPath) and not l.IsVisible] n_off = sum(1 for l in doc.Layers if (not l.IsDeleted) and not l.IsVisible) objs = doc.Objects.Count tmp = p + ".tmp.3dm" ok = bool(doc.WriteFile(tmp, Rhino.FileIO.FileWriteOptions())) doc.Dispose() r = {"layers_turned_on": len(changed), "still_off_that_reviewed_shows": still_off, "layers_off_now": n_off, "objects": objs, "written": ok} if ok: try: os.replace(tmp, p) r["saved"] = True except PermissionError: r["saved"] = False r["error"] = "file is locked (open in another Rhino window) - not overwritten" os.remove(tmp) return r for folder, rev, mod in PAIRS: try: res[mod] = fix_one(folder, rev, mod) except Exception: res[mod] = {"saved": False, "error": traceback.format_exc()} res["done"] = True json.dump(res, open(OUT, "w", encoding="utf-8"), ensure_ascii=False, indent=1)