# 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/ import copy JTMPL_FILEPATH = u"D:/Temp/JAC173IPM-Basic-03d.jtmpl" # Full path to the analysis template file def separateInfoTo3LinesFormat(serialInfoList): """Convert a single-column tuple into a tuple with three columns each""" resultList = [] tempInfo = ["name", "index", "type"] count = 1 for val in serialInfoList: if count % 3 == 1: tempInfo[0] = val elif count % 3 == 2: tempInfo[1] = val else: tempInfo[2] = val reservedInfo = copy.copy(tempInfo) resultList.append(reservedInfo) count += 1 return resultList def makePairIgnoreCaseDifferenceAndSpaces(unLinkedTemplateSide, unLinkedModelSide): """If names match with ignoring differences in capitalization and the presence or absence of spaces, then associate them""" pairArray = [] for tmplInfo in unLinkedTemplateSide: for modelInfo in unLinkedModelSide: # 0: name # 1: index # 2: type if tmplInfo[0].replace(" ", "").lower() == modelInfo[0].replace(" ", "").lower() and tmplInfo[2] == modelInfo[2]: for i in range(3): pairArray.append(tmplInfo[i]) for i in range(3): pairArray.append(modelInfo[i]) break return pairArray def checkParts(templateCtrl): """Regarding parts, retrieve all parts in the template and any parts that are not associated with the model""" print("Parts:") jtmplPartList = templateCtrl.GetPartsFromTemplate() # Since each component's information is represented by three columns, it is converted into a tuple of three columns for processing partsList = separateInfoTo3LinesFormat(jtmplPartList) # The values in the 3rd column: 0 represents a part, 1 represents a parts group partType = {"0": "Part", "1": "Group"} print("[partname], ", "[parttype]") for partInfo in partsList: partInfo[2] = partType[partInfo[2]] print(partInfo[0], ",", partInfo[2]) print("") allPaired = jtmplCtrl.IsAllPairsParts() if allPaired == False: unsetPartsInModelSide = jtmplCtrl.GetUnsetPartsFromSetting() if len(unsetPartsInModelSide) > 0: print("There are unlinked parts in model side.") unlinkedPart = separateInfoTo3LinesFormat(unsetPartsInModelSide) for partInfo in unlinkedPart: partInfo[2] = partType[partInfo[2]] print(" ", partInfo[0], ",", partInfo[2]) unsetPartsInTemplateSide = jtmplCtrl.GetUnsetPartsFromTemplate() if len(unsetPartsInTemplateSide) > 0: print("There are unlinked parts in template side.") unlinkedPart = separateInfoTo3LinesFormat(unsetPartsInTemplateSide) for partInfo in unlinkedPart: partInfo[2] = partType[partInfo[2]] print(" ", partInfo[0], ",", partInfo[2]) return allPaired # True if all are associated def checkSets(templateCtrl): """Regarding sets, retrieve all sets in the template and any sets that are not associated with the model""" print("Sets:") jtmplSetList = jtmplCtrl.GetSetsFromTemplate() # Since each component's information is represented by three columns, it is converted into a tuple of three columns for processing setList = separateInfoTo3LinesFormat(jtmplSetList) print("[setname], ", "[targettype]") for setInfo in setList: print(setInfo[0], ",", setInfo[2]) print("") allPaired = jtmplCtrl.IsAllPairsSets() if allPaired == False: unsetSetsInModelSide = jtmplCtrl.GetUnsetSetsFromSetting() if len(unsetSetsInModelSide) > 0: print("There are unlinked sets in model side.") unlinkedSet = separateInfoTo3LinesFormat(unsetSetsInModelSide) for setInfo in unlinkedSet: print(" ", setInfo[0], ",", setInfo[2]) unsetSetsInTemplateSide = jtmplCtrl.GetUnsetSetsFromTemplate() if len(unsetSetsInTemplateSide) > 0: print("There are unlinked sets in template side.") unlinkedSet = separateInfoTo3LinesFormat(unsetSetsInTemplateSide) for setInfo in unlinkedSet: print(" ", setInfo[0], ",", setInfo[2]) return allPaired # True if all are associated app = designer.GetApplication() targetModel = app.GetCurrentModel() jtmplCtrl = targetModel.CreateAnalysisTemplateControl(JTMPL_FILEPATH) fixedUpPairParts = [] fixedUpPairSets = [] partsPaired = checkParts(jtmplCtrl) if not partsPaired: # Compare the names of parts those were not automatically associated and creates an association if they match within the rules. unsetPartsInTemplateSide = jtmplCtrl.GetUnsetPartsFromTemplate() unsetPartsInModelSide = jtmplCtrl.GetUnsetPartsFromSetting() fixedUpPairParts = makePairIgnoreCaseDifferenceAndSpaces(separateInfoTo3LinesFormat( unsetPartsInTemplateSide), separateInfoTo3LinesFormat(unsetPartsInModelSide)) print("") setsPaired = checkSets(jtmplCtrl) if not setsPaired: # Compare the names of sets those were not automatically associated and creates an association if they match within the rules. unsetSetsInTemplateSide = jtmplCtrl.GetUnsetSetsFromTemplate() unsetSetsInModelSide = jtmplCtrl.GetUnsetSetsFromSetting() fixedUpPairSets = makePairIgnoreCaseDifferenceAndSpaces(separateInfoTo3LinesFormat( unsetSetsInTemplateSide), separateInfoTo3LinesFormat(unsetSetsInModelSide)) # Apply the analysis template to the model. Automatically associated pairs can be omitted from the arguments. targetModel.ImportAnalysisTemplateAuto(JTMPL_FILEPATH, fixedUpPairParts, fixedUpPairSets)