Danielm103 Posted 1 hour ago Posted 1 hour ago from pyrx import Ap, Ax, Db, Ed, Ge, Br # iter faces @Ap.Command() def doit1(): ps, id, _ = Ed.Editor.entSel("\nPick it: ", Db.Solid3d.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) dbs = Db.Solid3d(id) brs = Br.Brep(dbs) ft = Br.FaceTraverser(brs) for face in ft.getFaces(): print(face.getArea()) # iter edges @Ap.Command() def doit2() -> None: ps, id, pnt = Ed.Editor.entSel("\nSelect: ", Db.Solid3d.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("oof {}:".format(ps)) dbent = Db.Entity(id) brep = Br.Brep(dbent) et = Br.EdgeTraverser() et.setBrep(brep) while not et.done(): edge = et.getEdge() curveType = edge.getCurveType() excurve = Ge.ExternalCurve3d.cast(edge.getCurve()) if curveType == Ge.EntityId.kLineSeg3d: seg = Ge.LineSeg3d.cast(excurve.getNativeCurve()) print(seg.length(), seg.startPoint(), seg.endPoint()) elif curveType == Ge.EntityId.kCircArc3d: carc = Ge.CircArc3d.cast(excurve.getNativeCurve()) print(carc.center(), carc.radius()) et.next() # iter faces and edges @Ap.Command() def doit3() -> None: # 1. Prompt user to select a 3D solid ps, id, pnt = Ed.Editor.entSel("\nSelect Solid: ", Db.Solid3d.desc()) if ps != Ed.PromptStatus.eOk: raise RuntimeError("Selection failed: {}".format(ps)) # 2. Get the Solid entity and open its Boundary Representation (B-rep) dbs = Db.Solid3d(id) brs = Br.Brep(dbs) # 3. Step 1: Traverse the solid's Faces ft = Br.FaceTraverser(brs) face_index = 1 for face in ft.getFaces(): # --- NEW FACE METRIC EXTRACTION --- try: face_area = face.getArea() surf_type = face.getSurfaceType() # E.g., kPlane, kCylinder, etc. print(f"\n--- Face #{face_index} | Type: {surf_type} | Area: {face_area:.4f} ---") except Exception as e: print(f"\n--- Face #{face_index} (Failed to fetch area metrics: {e}) ---") face_index += 1 # ---------------------------------- # 4. Step 2: Step down from Face to its Loops flt = Br.FaceLoopTraverser() flt.setFace(face) while not flt.done(): loop = flt.getLoop() # 5. Step 3: Step down from Loop to its Edges (using LoopEdgeTraverser) let = Br.LoopEdgeTraverser() let.setLoop(loop) while not let.done(): edge = let.getEdge() # 6. Extract and evaluate the Edge geometry curveType = edge.getCurveType() excurve = Ge.ExternalCurve3d.cast(edge.getCurve()) if curveType == Ge.EntityId.kLineSeg3d: seg = Ge.LineSeg3d.cast(excurve.getNativeCurve()) print(" Line:", seg.length(), seg.startPoint(), seg.endPoint()) elif curveType == Ge.EntityId.kCircArc3d: carc = Ge.CircArc3d.cast(excurve.getNativeCurve()) print(" Arc:", carc.center(), carc.radius()) # Move to next Edge inside this loop let.next() # Move to next Loop inside this face flt.next() output for a 3d box Command: DOIT3 Select Solid: --- Face #1 | Type: kPlane | Area: 6095.4620 --- Line: 60.13854242043337 (103.70522552029884,68.98463275333243,46.66742774827728) (103.70522552029884,8.84609033289907,46.66742774827728) Line: 101.35699658327584 (2.34822893702299,68.98463275333243,46.66742774827728) (103.70522552029884,68.98463275333243,46.66742774827728) Line: 60.13854242043337 (2.34822893702299,8.84609033289907,46.66742774827728) (2.34822893702299,68.98463275333243,46.66742774827728) Line: 101.35699658327584 (103.70522552029884,8.84609033289907,46.66742774827728) (2.34822893702299,8.84609033289907,46.66742774827728) --- Face #2 | Type: kPlane | Area: 6095.4620 --- Line: 60.13854242043337 (103.70522552029884,8.84609033289907,0.00000000000000) (103.70522552029884,68.98463275333243,0.00000000000000) Line: 101.35699658327584 (2.34822893702299,8.84609033289907,0.00000000000000) (103.70522552029884,8.84609033289907,0.00000000000000) Line: 60.13854242043337 (2.34822893702299,68.98463275333243,0.00000000000000) (2.34822893702299,8.84609033289907,0.00000000000000) Line: 101.35699658327584 (103.70522552029884,68.98463275333243,0.00000000000000) (2.34822893702299,68.98463275333243,0.00000000000000) --- Face #3 | Type: kPlane | Area: 4730.0703 --- Line: 46.66742774827728 (2.34822893702299,68.98463275333243,46.66742774827728) (2.34822893702299,68.98463275333243,0.00000000000000) Line: 101.35699658327584 (2.34822893702299,68.98463275333243,46.66742774827728) (103.70522552029884,68.98463275333243,46.66742774827728) Line: 46.66742774827728 (103.70522552029884,68.98463275333243,46.66742774827728) (103.70522552029884,68.98463275333243,0.00000000000000) Line: 101.35699658327584 (103.70522552029884,68.98463275333243,0.00000000000000) (2.34822893702299,68.98463275333243,0.00000000000000) --- Face #4 | Type: kPlane | Area: 2806.5111 --- Line: 46.66742774827728 (2.34822893702299,8.84609033289907,46.66742774827728) (2.34822893702299,8.84609033289907,0.00000000000000) Line: 60.13854242043337 (2.34822893702299,8.84609033289907,46.66742774827728) (2.34822893702299,68.98463275333243,46.66742774827728) Line: 46.66742774827728 (2.34822893702299,68.98463275333243,46.66742774827728) (2.34822893702299,68.98463275333243,0.00000000000000) Line: 60.13854242043337 (2.34822893702299,68.98463275333243,0.00000000000000) (2.34822893702299,8.84609033289907,0.00000000000000) --- Face #5 | Type: kPlane | Area: 4730.0703 --- Line: 46.66742774827728 (103.70522552029884,8.84609033289907,46.66742774827728) (103.70522552029884,8.84609033289907,0.00000000000000) Line: 101.35699658327584 (103.70522552029884,8.84609033289907,46.66742774827728) (2.34822893702299,8.84609033289907,46.66742774827728) Line: 46.66742774827728 (2.34822893702299,8.84609033289907,46.66742774827728) (2.34822893702299,8.84609033289907,0.00000000000000) Line: 101.35699658327584 (2.34822893702299,8.84609033289907,0.00000000000000) (103.70522552029884,8.84609033289907,0.00000000000000) --- Face #6 | Type: kPlane | Area: 2806.5111 --- Line: 46.66742774827728 (103.70522552029884,68.98463275333243,46.66742774827728) (103.70522552029884,68.98463275333243,0.00000000000000) Line: 60.13854242043337 (103.70522552029884,68.98463275333243,46.66742774827728) (103.70522552029884,8.84609033289907,46.66742774827728) Line: 46.66742774827728 (103.70522552029884,8.84609033289907,46.66742774827728) (103.70522552029884,8.84609033289907,0.00000000000000) Line: 60.13854242043337 (103.70522552029884,8.84609033289907,0.00000000000000) (103.70522552029884,68.98463275333243,0.00000000000000) Quote
Danielm103 Posted 1 hour ago Author Posted 1 hour ago output for a cylinder Command: DOIT3 Select Solid: --- Face #1 | Type: kCylinder | Area: 428514.2140 --- Arc: (440.88076870446724,537.54943936113841,0.00000000000000) 198.3154183465131 Arc: (440.88076870446724,537.54943936113841,343.89739291260162) 198.3154183465131 --- Face #2 | Type: kPlane | Area: 123555.7137 --- Arc: (440.88076870446724,537.54943936113841,0.00000000000000) 198.3154183465131 --- Face #3 | Type: kPlane | Area: 123555.7137 --- Arc: (440.88076870446724,537.54943936113841,343.89739291260162) 198.3154183465131 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.