# 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/ def getPartsInBoxArea(model, diagonalPoint1, diagonalPoint2): """Select parts located within the box defined by a diagonal connecting the two points specified as arguments with sides parallel to the x, y, or z-axes. """ result = model.CreateSelection() result.Clear() result.Attach() # The 3rd argumet of SelectPartByRange # False: Select all parts in the range # True: Select only visible parts in the range result.SelectPartByRange(diagonalPoint1, diagonalPoint2, False) return result app = designer.GetApplication() model = app.GetCurrentModel() point1 = app.CreatePoint(-40, -40, 0) point2 = app.CreatePoint(42, 42, 60) selParts = getPartsInBoxArea(model, point1, point2) model.GetGroupList().CreateGroupBySelected(selParts, "newGroup")