# 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 getConditionsSpecifiedType(targetStudy, typeName): """Get specified type conditions applied to the target study""" matches = [] numConds = targetStudy.NumConditions() for i in range(numConds): condition = targetStudy.GetCondition(i) CondType = condition.GetScriptTypeName() if CondType == typeName: matches.append(condition) return matches def findTargetColumnByConditionName(targetStudy, targetResultTableData, referenceCondTypeName): """Retrieve the desired column number from the table format result where column names are determined by the tilte of the analysis condition""" ret = -1 conditions = getConditionsSpecifiedType(targetStudy, referenceCondTypeName) if len(conditions) <= 0: print(u"Reference condition is not found.") else: # Search for the column using the title of the first condition found nameToFind = conditions[0].GetName() for col in range(0, targetResultTableData.GetCols()): if targetResultTableData.GetColName(col) == nameToFind: ret = col break return ret def setOriginalResponseValue(varName, targetStudy, targetCaseNo): """Register the rotation angle at the maximum torque as a user-defined response value.""" torqueData = targetStudy.GetResultTable().GetData(u"Torque") if not torqueData.IsValid(): print(u"Torque result doesn't exist.") return # Search for the column number to refer to by the tile of the Torque:Nodal Force condition targetColNo = findTargetColumnByConditionName(targetStudy, torqueData, u"Torque") if targetColNo <= -1: print(u"Column is not found.") return maxTorque = torqueData.GetValue(0, targetColNo) maxRow = 0 # Find the row number where the torque is maximum for row in range(1, torqueData.GetRows()): if maxTorque < torqueData.GetValue(row, targetColNo): maxTorque = torqueData.GetValue(row, targetColNo) maxRow = row # Get the rotation angle of the obtained row number angleAtMaxTorque = torqueData.GetAngle(maxRow) print(varName, angleAtMaxTorque) targetStudy.SetUserResponseVariable(varName, targetCaseNo, angleAtMaxTorque) app = designer.GetApplication() responseVarName = u"Angle_atMaxTorque" study = app.GetCurrentStudy() caseNo = study.GetCurrentCase() setOriginalResponseValue(responseVarName, study, caseNo)