#--------------------------------------------------------------------- #Name: d0031_set_fem_conductors.py #Menu-en: Set FEM Conductors for Parts in a set #Menu-ja: 部品セットにFEMコンダクタを設定する #Type: Python #Create: January 24, 2017 JSOL Corporation #Comment-en: This script set FEM conductor conditions on all wires of a set in the current study. Requires V15.1 or later. #Comment-ja: 素線のセット名を指定し、現在のスタディで素線一束分のFEMコンダクタ条件を設定する。バージョン15.1以降が必要です。 #Copyright: (c) JSOL Corporation. All Rights Reserved. #--------------------------------------------------------------------- def main(): app = designer.GetApplication() if check_HasResult(app) == True: return set_FEM_element_main(app) def set_FEM_element_main(app): dimension = app.GetCurrentModel().GetDimension() if dimension == 2: set_FEM_element_2D(app) elif dimension == 3: set_FEM_element_3D(app) def set_FEM_element_2D(app): dialogbox = app.CreateDialogBox() if create_dialogbox_2D(app, dialogbox) == 1: if has_set(app, dialogbox) == True: if is_set_Part(app, dialogbox) == True: setname = dialogbox.GetValue("SetName").decode('utf-8') setParts = app.GetCurrentModel().GetSetList().GetSet(setname) setIDs = setParts.GetIDs() direct = dialogbox.GetValue("Direction") study = app.GetCurrentStudy() condition = study.CreateCondition("FEMConductor", "wires for " + setname) for i in range (0, setParts.NumParts()): if 0 < i : condition.CreateSubCondition("FEMConductorData", "wire") subcondition = condition.GetSubCondition(i) subcondition.SetName("wire" + "_" + str((i+1))) subcondition.ClearParts() sel = subcondition.GetSelection() sel.SelectPart(setIDs[i]) subcondition.AddSelected(sel) subcondition.SetValue("Direction2D", direct) create_circuit(study, condition, setname) def set_FEM_element_3D(app): dialogbox = app.CreateDialogBox() if create_dialogbox_3D(app, dialogbox) == 1: if has_set(app, dialogbox) == True: if is_set_Face(app, dialogbox) == True: setname = dialogbox.GetValue("SetName").decode('utf-8') setFaces = app.GetCurrentModel().GetSetList().GetSet(setname) setIDs = setFaces.GetIDs() model = app.GetCurrentModel() study = app.GetCurrentStudy() condition = study.CreateCondition("FEMConductor", "wires for " + setname) for i in range (0, setFaces.NumParts()): if 0 < i: condition.CreateSubCondition("FEMConductorData", "wire") subcondition = condition.GetSubCondition(i) subcondition.SetName("wire" + "_" + str((i+1))) subcondition.ClearParts() sel = subcondition.GetSelectionByGroup(0) sel.SelectFace(setIDs[i]) subcondition.AddSelectedByGroup(sel, 0) point = model.GetFaceCentroidPosition(setIDs[i]) sel = subcondition.GetSelectionByGroup(2) sel.SelectPartByPosition(point.GetX(),point.GetY(),point.GetZ()) subcondition.AddSelectedByGroup(sel, 2) create_circuit(study, condition, setname) def create_dialogbox_2D(app, dialogbox): message = "This script set FEM conductor conditions on all wires of a set in the current study.
" message = message + "
" + " - Only for one bundle of wires." message = message + "
" + " - A set of parts needs to be prepared in advance.

" message_jp = "現在のスタディの中の指定したセットに含まれる素線にFEMコンダクタを設定します。
" message_jp = message_jp + "
" + " ・ コイル素線1束分の設定をおこないます。" message_jp = message_jp + "
" + " ・ 前もって素線部品のセットを作成しておく必要があります。

" title = "Automatic FEM Conductor Condition Setting for Wires 2D" setlbl = "Name of Set" title_jp = "指定したセットに含まれる素線にFEMコンダクタ条件を設定する" setlbl_jp = "素線のセット名" study = app.GetCurrentStudy() if study.IsAxisymmetricStudy() == True: dirOptlbl0 = "+ Theta" dirOptlbl1 = "- Theta" dirOptlbl0_jp = "奥向き" dirOptlbl1_jp = "手前向き" else: dirOptlbl0 = "Upward" dirOptlbl1 = "Downward" dirOptlbl0_jp = "上向き" dirOptlbl1_jp = "下向き" dialogbox.SetTranslation(title, title_jp) dialogbox.SetTranslation(message, message_jp) dialogbox.SetTranslation(setlbl, setlbl_jp) dialogbox.SetTranslation(dirOptlbl0, dirOptlbl0_jp) dialogbox.SetTranslation(dirOptlbl1, dirOptlbl1_jp) dialogbox.SetTitle(title) dialogbox.AddLabel(message) dialogbox.AddString("SetName", setlbl, "Coils", 0, 1) dialogbox.AddRadio("Direction",dirOptlbl0, 0) dialogbox.AddRadio("Direction",dirOptlbl1, 1) create_dialogbox_2D = dialogbox.Show() return create_dialogbox_2D def create_dialogbox_3D(app, dialogbox): message = "This script set FEM conductor conditions on all wires of a set in the current study.
" message = message + "
" + " - Only for one bundle of wires." message = message + "
" + " - A set of inflow faces needs to be prepared in advance.

" message_jp = "現在のスタディの中の指定したセットに含まれる素線にFEMコンダクタを設定します。
" message_jp = message_jp + "
" + " ・ コイル素線1束分の設定をおこないます。" message_jp = message_jp + "
" + " ・ 前もって素線部品に電流が流入する面のセットを作成しておく必要があります。

" title = "Automatic FEM Conductor Condition Setting for Wires 3D" setlbl = "Name of the Set for Inflow faces" title_jp = "指定したセットに含まれる素線にFEMコンダクタ条件を設定する" setlbl_jp = "素線流入面のセット名" dialogbox.SetTranslation(title, title_jp) dialogbox.SetTranslation(message, message_jp) dialogbox.SetTranslation(setlbl, setlbl_jp) dialogbox.SetTitle(title) dialogbox.AddLabel(message) dialogbox.AddString("SetName", setlbl, "inflow", 0, 1) create_dialogbox_3D = dialogbox.Show() return create_dialogbox_3D; def has_set(app, dialogbox): setname = dialogbox.GetValue("SetName").decode('utf-8') set_temp = app.GetCurrentModel().GetSetList().GetSet(setname) if 0 < set_temp.NumParts(): flag = True else: flag = False message_does_not_exist_set(app, setname) has_set = flag return has_set def is_set_Part(app, dialogbox): setname = dialogbox.GetValue("SetName").decode('utf-8') if get_set_type(app, dialogbox) == "Part": flag = True else: flag = False message_set_does_not_include_Parts(app, setname) is_set_Part = flag return is_set_Part def is_set_Face(app, dialogbox): setname = dialogbox.GetValue("SetName").decode('utf-8') if get_set_type(app, dialogbox) == "Face": flag = True else: flag = False message_set_does_not_include_Faces(app, setname) is_set_Face = flag return is_set_Face def get_set_type(app, dialogbox): setname = dialogbox.GetValue("SetName").decode('utf-8') set_temp = app.GetCurrentModel().GetSetList().GetSet(setname) set_type = set_temp.GetType() get_set_type = set_type return get_set_type def message_does_not_exist_set(app, setname): msgdlg = app.CreateDialogBox() title = "Error" message = "The set (" + setname + ") does not exist." title_jp = "エラー" message_jp = u"入力した " + setname + u" という名前のセットは存在しません。" msgdlg.SetTranslation(title, title_jp) msgdlg.SetTranslation(message, message_jp) msgdlg.SetCancelButtonVisible(False) msgdlg.SetTitle(title) msgdlg.AddLabel(message) message_does_not_exist_set = msgdlg.Show() return message_does_not_exist_set def message_set_does_not_include_Parts(app, setname): msgdlg = app.CreateDialogBox() title = "Error" message = "The set (" + setname + ") is not a set of Parts." title_jp = "エラー" message_jp = u"入力した " + setname + u" は 部品 のセットではありません。" msgdlg.SetTranslation(title, title_jp) msgdlg.SetTranslation(message, message_jp) msgdlg.SetCancelButtonVisible(False) msgdlg.SetTitle(title) msgdlg.AddLabel(message) message_set_does_not_include_Parts = msgdlg.Show() return message_set_does_not_include_Parts def message_set_does_not_include_Faces(app, setname): msgdlg = app.CreateDialogBox() title = "Error" message = "The set (" + setname + ") is not a set of Faces." title_jp = "エラー" message_jp = u"入力した " + setname + u" は 面 のセットではありません。面のセットを指定してください。" msgdlg.SetTranslation(title, title_jp) msgdlg.SetTranslation(message, message_jp) msgdlg.SetCancelButtonVisible(False) msgdlg.SetTitle(title) msgdlg.AddLabel(message) message_set_does_not_include_Faces = msgdlg.Show() return message_set_does_not_include_Faces def create_circuit(study, targetCond, compNamePostFix): if study.HasCircuit() == True: circuit = study.GetCircuit() else: circuit = study.CreateCircuit() circuit.CreateComponent("FEMConductor", "bundle of wires component") circuit.CreateInstance("bundle of wires component", 1, 6) compName = "bundle of wires for " + compNamePostFix circuit.GetComponent("bundle of wires component").SetName(compName) targetCond.SetLink(compName) def check_HasResult(app): targetStudy = app.GetCurrentStudy() check_HasResult = False if targetStudy.AnyCaseHasResult() == True: check_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 check_HasResult if __name__ == "__main__": main()