[D0030] 選択中の部品へ渦電流を考慮する

 

選択された部品に対して、[渦電流を考慮する]フラグを設定する。

import designer

app = designer.GetApplication()

def main():
	if check_HasResult(app) == True:
		return

	if is_study_type_magnetic() == False:
		return
	if is_selected_any_parts() == False:
		return

	if initial_notice() is True:
		return

	set_parts_eddy_current_on()


def set_parts_eddy_current_on():
	flag_name = "EddyCurrentCalculation"
	view = app.View()
	sel = view.GetCurrentSelection()
	study = app.GetCurrentStudy()
	parts_num = sel.NumParts()

	for i in range(0, parts_num):
		study.GetMaterial(sel.PartID(i)).SetValue(flag_name, 1)

	view.ClearSelect()

def is_study_type_magnetic():

	str = "Magnetic"
	str_ja = "磁界"
	study_type = app.GetCurrentStudy().GetType()
	if str in study_type or str_ja in study_type:
		return True
	else:
		message_is_not_study_type_magnetic()
		return False


def  message_is_not_study_type_magnetic():
	msgdlg = app.CreateDialogBox()
	title = "Error"
	message = "The study type is not a magnetic analysis study."

	title_jp = "エラー"
	message_jp = " スタディタイプは磁界解析ではありません。"

	msgdlg.SetTranslation(title, title_jp)
	msgdlg.SetTranslation(message, message_jp)
	msgdlg.SetCancelButtonVisible(False)

	msgdlg.SetTitle(title)
	msgdlg.AddLabel(message)

	msgdlg.Show()



def is_selected_any_parts():
	sel = app.View().GetCurrentSelection()
	if 0 < sel.NumParts():
		return True
	else:
		message_do_not_select_parts()
		return False


def message_do_not_select_parts():
	msgdlg = app.CreateDialogBox()

	title = "Error"
	message = "No parts are selected."

	title_jp = "エラー"
	message_jp = "部品が選択されていません。"

	msgdlg.SetTranslation(title, title_jp)
	msgdlg.SetTranslation(message, message_jp)
	msgdlg.SetCancelButtonVisible(False)

	msgdlg.SetTitle(title)
	msgdlg.AddLabel(message)

	msgdlg.Show()


def initial_notice():
	confirmDlg = app.CreateDialogBox()

	title = "Set Eddy current flag on"
	message = "This script will set the eddy current calculation flag on all the selected parts.
" message = message + "
" + " - air parts will be excluded." message = message + "
" + "
" + "Do you want to run?" title_jp = "渦電流を考慮するフラグをONにします" message_jp = "現在のスタディの中の選択した部品の渦電流を考慮するフラグをONに設定します。
" 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 = app.GetCurrentStudy() 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()

Download Python source code

ファイルご利用の注意点

JMAGスクリプトライブラリをご利用されるに際し、以下の利用規約をよくお読みいただき、ご同意の上ご利用下さるようお願い申し上げます。