#--------------------------------------------------------------------- #Name: d0008_coil_to_conductor.py #Menu-en: Switch all FEM coils to FEM conductors #Menu-ja: FEMコイルをFEMコンダクタに変換 #Type: Python #Create: May 31, 2016 JSOL Corporation #Comment-en: This script will replace all FEM coils with FEM conductor in the current study. Requires Version 15.1 or later. #Comment-ja: 現在のスタディに設定されたFEMコイルをFEMコンダクタに置き換える。バージョン15.1以降が必要です。 #Copyright: (c) JSOL Corporation. All Rights Reserved. #--------------------------------------------------------------------- import designer TARGET_COND_TYPE = "FEMCoil" SWITCH_TO_COND_TYPE = "FEMConductor" SWITCH_TO_COMP_TYPE = "FEMConductor" SWITCH_TO_COND_SUB_TYPE = "FEMConductorData" DIRECTION_TYPE_KEY = "DirectionType" DIRECTION_TYPE_2D_KEY = "Direction2D" COIL_FLOWINFACE_VALUE = 0 CONDUCTOR_PARTSINFLOW_VALUE = 1 EDDY_CURRENT_FLAG = "EddyCurrentCalculation" app = designer.GetApplication() def main(): targetStudy = app.GetCurrentStudy() if check_HasResult(app, targetStudy) == True: return if initial_notice() != 0: return targetModel = app.GetCurrentModel() switch_main(targetModel, targetStudy) def switch_main(targetModel, targetStudy): dimension = targetModel.GetDimension() hitCount = 0 targetCondIndices = [] numCond = targetStudy.NumConditions() for i in range(0,numCond): currentCond = targetStudy.GetCondition(i) condTypeName = currentCond.GetScriptTypeName() if condTypeName == TARGET_COND_TYPE: hitCount = hitCount + 1 targetCondIndices.append(hitCount) targetCondIndices[len(targetCondIndices)-1] = i if dimension == 2: create_switch_cond_2D(targetStudy, currentCond) elif dimension == 3: create_switch_cond_3D(targetStudy, currentCond) if hitCount > 0: i = hitCount while i > 0: targetStudy.DeleteCondition(targetCondIndices[i-1]) i = i - 1 def create_switch_cond_3D(targetStudy, orgCond): numOrgSubCond = orgCond.NumSubConditions() newCond = targetStudy.CreateCondition(SWITCH_TO_COND_TYPE, orgCond.GetName()) for i in range(0, numOrgSubCond): orgSubCond = orgCond.GetSubCondition(i) newSubCond = newCond.CreateSubCondition(SWITCH_TO_COND_SUB_TYPE, orgSubCond.GetName()) newSubCond.SetValue(DIRECTION_TYPE_KEY, CONDUCTOR_PARTSINFLOW_VALUE) partSel = orgSubCond.GetSelection() newSubCond.AddSelectedByGroup(partSel, 2) numParts = partSel.NumParts() for j in range (0, numParts): targetStudy.GetMaterial(partSel.PartID(j)).SetValue(EDDY_CURRENT_FLAG, 1) dirType = orgSubCond.GetValue(DIRECTION_TYPE_KEY) if dirType == COIL_FLOWINFACE_VALUE: newSubCond.AddSelectedByGroup(orgSubCond.GetSecondarySelection(), 0) numNewSubCond = newCond.NumSubConditions() if numNewSubCond > numOrgSubCond: for i in range(0, numNewSubCond - numOrgSubCond): newCond.RemoveSubCondition(i) replace_circuit_instance(targetStudy, orgCond, newCond) def create_switch_cond_2D(targetStudy, orgCond): numOrgSubCond = orgCond.NumSubConditions() newCond = targetStudy.CreateCondition(SWITCH_TO_COND_TYPE, orgCond.GetName()) for i in range (0, numOrgSubCond): orgSubCond = orgCond.GetSubCondition(i) newSubCond = newCond.CreateSubCondition(SWITCH_TO_COND_SUB_TYPE, orgSubCond.GetName()) sel = orgSubCond.GetSelection() newSubCond.AddSelected(sel) numParts = sel.NumParts() for j in range (0, numParts): targetStudy.GetMaterial(sel.PartID(j)).SetValue(EDDY_CURRENT_FLAG, 1) newSubCond.SetValue(DIRECTION_TYPE_2D_KEY, orgSubCond.GetValue(DIRECTION_TYPE_2D_KEY)) numNewSubCond = newCond.NumSubConditions() if numNewSubCond > numOrgSubCond: for i in range (0, numNewSubCond - numOrgSubCond): newCond.RemoveSubCondition(i) replace_circuit_instance(targetStudy, orgCond, newCond) def replace_circuit_instance(targetStudy, orgCond, newCond): if targetStudy.HasCircuit() == False: return currentCircuit = targetStudy.GetCircuit() linkCompName = orgCond.GetLink() targetComp = currentCircuit.GetComponent(linkCompName) targetCompInst = currentCircuit.GetInstance(linkCompName, 0) if app.HasError() == True: app.ClearError() return orgCompName = targetComp.GetName() newCompName = "Switch_From_"+orgCompName orgPos = targetCompInst.GetPosition() orgAngle = targetCompInst.GetAngle() newComp = currentCircuit.CreateComponent(SWITCH_TO_COMP_TYPE, newCompName) newCompInst = currentCircuit.CreateInstance(newCompName, int(orgPos.GetX()), int(orgPos.GetY())) newCompInst.RotateTo(orgAngle) newCond.SetLink(newCompName) currentCircuit.DeleteComponent(linkCompName) def initial_notice(): confirmDlg = app.CreateDialogBox() title = "Convert FEM Coils to FEM Conductors" message = "This script will replace all FEM coils with FEM conductors.
" message = message + "
" + "-Note that FEM Coils inside macro circuits will not be replaced." message = message + "
" + "-For FEM Coils that are set using a direction vector instead of an Inflow face the outflow face of the FEM coil will not be set." message = message + "
" + "-Also, coil groups will be removed." message = message + "
" + "
" + "Do you want to run?" title_jp = "FEMコイルのFEMコンダクタへの置換" message_jp = "現在のスタディのFEMコイルをFEMコンダクタに置き換えます。
" message_jp = message_jp + "
" + "-マクロ素子内のFEMコイルに関連付けられている場合、関連付けがされません。" message_jp = message_jp + "
" + "-3次元で通電タイプがベクトルの場合、流入面が設定されません。" message_jp = message_jp + "
" + "-グループ化は解除されます。" message_jp = message_jp + "
" + "
" + "実行しますか?" confirmDlg.SetTranslation(title, title_jp) confirmDlg.SetTranslation(message, message_jp) confirmDlg.SetTitle(title) confirmDlg.AddLabel(message) confirmDlg.Show() return confirmDlg.WasCancelled() def check_HasResult(app, targetStudy): hasResult = False if targetStudy.AnyCaseHasResult() == True: hasResult = True errorDlg = app.CreateDialogBox() title_jp = "エラー" message_jp = "結果を持つケースがあります。" title = "Error" message = "There are some cases those have result in this study." errorDlg.SetTranslation(title, title_jp) errorDlg.SetTranslation(message, message_jp) errorDlg.SetCancelButtonVisible(False) errorDlg.SetTitle(title) errorDlg.AddLabel(message) errorDlg.Show() return hasResult main()