# 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() # Target part name for material synchronization TargetPartName = u"Magnet" def getMaterialParametricItem(designTable, partName): """Obtain the material parametric item of the specified part from the DesignTable.""" for parameterIndex in range(designTable.NumParameters()): if not designTable.IsMaterialItem(parameterIndex): continue parameterName = designTable.ParameterName(parameterIndex) if parameterName.startswith(partName + u":"): return designTable.GetMaterialParametricItem(parameterName) def getMaterialParametricItems(analysisGroup, partName): """Obtain the material parametric items of the specified part from all studies in the analysis group.""" materialItems = [] for studyIndex in range(analysisGroup.NumStudies()): study = analysisGroup.GetStudy(studyIndex) materialItem = getMaterialParametricItem( study.GetDesignTable(), partName ) if materialItem is not None: materialItems.append(materialItem) return materialItems def syncMaterialParametricItems(designTable, materialItems): """Synchronize the specified material parametric items.""" referenceItem = designTable.CreateReferenceItem(materialItems[0]) for materialItem in materialItems[1:]: referenceItem.AddParametricItemObject(materialItem) referenceItem.Build() def main(): """Synchronize the material of the specified part across the studies in the analysis group.""" analysisGroup = app.GetCurrentAnalysisGroup() designTable = analysisGroup.GetDesignTable() materialItems = getMaterialParametricItems( analysisGroup, TargetPartName ) if len(materialItems) < 2: print("Error: Material parametric items for the target part were found in fewer than two studies.") return syncMaterialParametricItems(designTable, materialItems) main()