[S0038] Retrieve the parts and sets information of the analysis template, associate them and apply to a model

Analysis template is a function that allows to reuse analysis settings such as studies, conditions, and circuits to other models.
When applying an analysis template, it is needed to specify pairs of parts or entities to be used for setting materials and conditions.
For entities such as faces and edges, sets must be created in advance.
If the names of parts or sets match between the analysis template and the model to which it is applied, pairs will be created automatically.
This script retrieves information on parts and sets from the analysis template and retrieves pairs that are not automatically associated.
Then, if the names match except for differences in capitalization and the presence or absence of spaces, it creates a pair and applies the analysis template with the created pair information.

Preconditions

  • The model to which the analysis template will be applied has been created.
    This script runs for the active model in the project tree.
  • Parts and sets are handled to associate between the analysis template and the model.

Script Function

  • Retrieve and display information about the parts in the analysis template.
  • Display parts in the model that are not automatically associated with the analysis template.
  • Display parts in the analysis template that are not automatically associated with the model.
  • Create associations for parts that were not automatically associated, if the only differences are in case sensitivity and the presence or absence of space.
  • Retrieve and display information about the sets in the analysis template.
  • Display sets in the model that are not automatically associated with the analysis template.
  • Display sets in the analysis template that are not automatically associated with the model.
  • Create associations for sets that were not automatically associated, if the only differences are in case sensitivity and the presence or absence of space.
  • Apply the analysis template with the created association information.
# 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)

Download Python source code

How to use script file

Use the JMAG Script Library after reading and agreeing to the following terms of use.

Search Filter
  • All Categories

An engineer's diary
JMAG-Express Online