# Copyright (c) 2026 JSOL CORPORATION # # This script is released under the MIT License. # See the full license text at: # https://www.jmag-international.com/scriptlibrary/jmag_script_library_mit/ app = designer.GetApplication() def createCylinderAreaToSelect(): """Define a cylindrical region using a Cylinder object """ pointOnCenterAxis = app.CreatePoint(0, 0, 0) centerAxisDirection = app.CreatePoint(0, 0, 1) InnerR = 20 OuterR = 50 HTop = 70 HBottom = 0 XAxisDirection = app.CreatePoint(1, 0, 0) startAngle = 0 endAngle = 90 cyl = app.CreateCylinder() cyl.SetCenterPointByPoint(pointOnCenterAxis) cyl.SetCenterAxisByPoint(centerAxisDirection) cyl.SetOuterRadius(OuterR) cyl.SetInnerRadius(InnerR) cyl.SetUseHeight(True) cyl.SetHeightTop(HTop) cyl.SetHeightBottom(HBottom) cyl.SetUseAngle(True) cyl.SetXAxisByPoint(XAxisDirection) cyl.SetStartAngle(startAngle) cyl.SetEndAngle(endAngle) return cyl def getFacesInCylinderArea(model, cylinder): """Select faces located within the cylindrical region """ sel = model.CreateSelection() sel.Clear() sel.Attach() # The 2rd argumet of SelectFaceByCylinderObject # False: Select all parts in the range # True: Select only visible parts in the range sel.SelectFaceByCylinderObject(cylinder, False) return sel def filterFacesByNormalToZAxis(model, faceSelection): """From the selected faces, re-select only those with normals parallel to the Z-axis """ roundDigits = 7 faceSelection.Detach() newSel = model.CreateSelection() newSel.Clear() for i in range(faceSelection.NumFaces()): fid = faceSelection.FaceID(i) nv = model.GetFaceNormalVector(fid) if round(nv.GetX(), roundDigits) == 0.0 and round(nv.GetY(), roundDigits) == 0.0: newSel.SelectFace(fid) return newSel cylinderArea = createCylinderAreaToSelect() model = app.GetCurrentModel() selFaces = getFacesInCylinderArea(model, cylinderArea) filteredFaces = filterFacesByNormalToZAxis(model, selFaces) print(filteredFaces.NumFaces())