# -*- coding: utf-8 -*- # 07_ctc_extract.py (대호지교 P1, 2026-10-06 검증) # 목적: 철근 마크별 리프 Brep 중심점을 코핑 로컬 좌표 (s=길이방향, t=폭방향, z)로 뽑아 JSON 저장. # 이후 PowerShell/awk로 고유값 정렬 -> 차이 = 도면 @간격(CTC)과 대조. # - 주철근: 고유 t 의 차이 (폭방향 간격) # - 스터럽(C12~C18): 고유 s 의 차이 (길이방향 간격) - 주의: 뚜껑/바닥 조각은 s가 서로 다를 수 있으니 클러스터 시작값만 쓰지 말 것 # - C25 등 ⊓: 고유 s (길이방향) 와 z (단 간격) # 실행: 마크 하나(MARKS 1~2개)씩 돌릴 것. 전체를 한 번에 하면 AreaMassProperties 때문에 소켓 타임아웃. # 타임아웃이 나도 스크립트는 Rhino 안에서 계속 도므로, 결과 파일이 생길 때까지 기다린다(백그라운드 until 루프). import Rhino, json, io, os, math import scriptcontext as sc doc = sc.doc MARKS = ["C1", "C2", "C3"] OX, OY = 480714926.0, 153833329.5 ANG = math.atan2(4255.0, 12284.0) ca = math.cos(ANG) sa = math.sin(ANG) folder = os.path.dirname(doc.Path) out = os.path.join(folder, "ctc_points_" + "_".join(MARKS) + ".json") es = Rhino.DocObjects.ObjectEnumeratorSettings() es.HiddenObjects = True # 꺼진 레이어 객체 포함 es.NormalObjects = True es.LockedObjects = True res = {} for o in doc.Objects.GetObjectList(es): g = o.Geometry ly = doc.Layers[o.Attributes.LayerIndex].FullPath if "CYCLE" not in ly: continue mk = ly.split("::")[-1].split("_")[0] if mk not in MARKS: continue pts = res.get(mk, []) leaves = [] if isinstance(g, Rhino.Geometry.InstanceReferenceGeometry): stack = [[doc.InstanceDefinitions.FindId(g.ParentIdefId), g.Xform]] while len(stack) > 0: item = stack.pop() for ob in item[0].GetObjects(): og = ob.Geometry if isinstance(og, Rhino.Geometry.InstanceReferenceGeometry): stack.append([doc.InstanceDefinitions.FindId(og.ParentIdefId), item[1] * og.Xform]) elif isinstance(og, Rhino.Geometry.Brep): c = Rhino.Geometry.AreaMassProperties.Compute(og).Centroid c.Transform(item[1]) # 중첩 변환: 월드 = 부모 * 자식 * 점 leaves.append(c) elif isinstance(g, Rhino.Geometry.Brep): # C26처럼 인스턴스가 아닌 낱개 Brep leaves.append(Rhino.Geometry.AreaMassProperties.Compute(g).Centroid) for c in leaves: dx = c.X - OX dy = c.Y - OY pts.append([round(dx * ca + dy * sa, 1), round(-dx * sa + dy * ca, 1), round(c.Z, 1)]) res[mk] = pts txt = json.dumps(res) f = io.open(out, "w", encoding="utf-8") try: f.write(txt) except TypeError: f.write(txt.decode("utf-8")) f.close()