# 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 getOrCreatePartSet(model, setNm): """Gets or creates the set passed as an argument""" partSet = model.GetSetList().GetSet(setNm) partSet = partSet if partSet.IsValid() else model.GetSetList().CreatePartSet(setNm) return partSet def setParts(partSet, partsNmArray): """Sets the parts passed as arguments to the set""" partSet.SetMatcherType(u"Selection") partSet.SetUpdateByRelation(False) partSet.ClearParts() sel = partSet.GetSelection() for partsNm in partsNmArray: sel.SelectPart(partsNm) partSet.AddSelected(sel) app = designer.GetApplication() model = app.GetCurrentModel() setNm = u"coilSet" partSet = getOrCreatePartSet(model, setNm) partsNmArray = [u"Coil2", u"Coil4"] setParts(partSet, partsNmArray)