[D0010] FEMコンダクタをFEMコイルに変換

 

現在のスタディに設定されたFEMコンダクタをFEMコイルに置き換える。バージョン15.1以降が必要です。

import designer

TARGET_COND_TYPE = "FEMConductor"
SWITCH_TO_COND_TYPE = "FEMCoil"
SWITCH_TO_COMP_TYPE = "Coil"
SWITCH_TO_COND_SUB_TYPE = "FEMCoilData"
DIRECTION_TYPE_KEY = "DirectionType"
DIRECTION_TYPE_2D_KEY = "Direction2D"
COIL_FLOWINFACE_VALUE = 0
CONDUCTOR_PARTSINFLOW_VALUE = 1

TURN_VAL_NAME = "Turn"
RESISTANCE_VAL_NAME = "Resistance"
LEAKAGE_INDUCTANCE_VAL_NAME = "LeakageInductance"
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()
	paramInputDlg = app.CreateDialogBox()
	setup_param_input_dialog(app, paramInputDlg)

	switch_main(targetModel, targetStudy, paramInputDlg)

def setup_param_input_dialog(app, dialog):

	title_jp = "FEMコイル素子の設定値"
	turnlbl_jp = "巻き数"
	resistancelbl_jp = "抵抗一定値"
	leakageinductancelbl_jp = "漏れインダクタンス"

	title = "Setting value of FEM Coil Component"
	turnlbl = "Turn"
	resistancelbl = "Resistance"
	leakageinductancelbl = "Leakage Inductance"

	dialog.SetTranslation(title, title_jp)
	dialog.SetTranslation(turnlbl, turnlbl_jp)
	dialog.SetTranslation(resistancelbl, resistancelbl_jp)
	dialog.SetTranslation(leakageinductancelbl, leakageinductancelbl_jp)

	dialog.SetTitle(title)
	dialog.AddReal(TURN_VAL_NAME, turnlbl, 1.0)
	dialog.AddReal(RESISTANCE_VAL_NAME, resistancelbl, 1.0)
	dialog.AddReal(LEAKAGE_INDUCTANCE_VAL_NAME, leakageinductancelbl, 0.0)
	dialog.SetCancelButtonVisible(False)

def switch_main(targetModel, targetStudy, inputDlg):

	targetCondIndices=[]

	dimension = targetModel.GetDimension()
	hitCount = 0
	numCond = targetStudy.NumConditions()
	for i in range(0, numCond):
		currentCond = targetStudy.GetCondition(i)
		condTypeName = currentCond.GetScriptTypeName()
		if condTypeName == TARGET_COND_TYPE:
			hitCount = hitCount + 1
			if hitCount == 1:
				inputDlg.Show()
			targetCondIndices.append(hitCount)
			targetCondIndices[-1] = i
			if dimension == 2:
				create_switch_cond_2D(targetStudy, currentCond, inputDlg)
			elif dimension == 3:
				create_switch_cond_3D(targetStudy, currentCond, inputDlg)


	if hitCount > 0:
		i = hitCount
		while i > 0:
			targetStudy.DeleteCondition(targetCondIndices[i-1])
			i = i - 1

def create_switch_cond_3D(targetStudy, orgCond, inputDlg):
	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, COIL_FLOWINFACE_VALUE)

		newSubCond.AddSecondarySelected(orgSubCond.GetSelectionByGroup(0))
		dirType = orgSubCond.GetValue(DIRECTION_TYPE_KEY)
		if dirType == CONDUCTOR_PARTSINFLOW_VALUE:
			partSel = orgSubCond.GetSelectionByGroup(2)
			newSubCond.AddSelected(partSel)
			numParts = partSel.NumParts()
			for j in range (0, numParts):
				targetStudy.GetMaterial(partSel.PartID(j)).SetValue(EDDY_CURRENT_FLAG, 0)

	numNewSubCond = newCond.NumSubConditions()
	if numNewSubCond > numOrgSubCond:
		for i in range(0, numNewSubCond - numOrgSubCond):
			newCond.RemoveSubCondition(i)

	replace_circuit_instance(targetStudy, orgCond, newCond, inputDlg)

def create_switch_cond_2D(targetStudy, orgCond, inputDlg):
	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, 0)
		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, inputDlg)


def replace_circuit_instance(targetStudy, orgCond, newCond, inputDlg):
	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)
	newComp.SetValue(TURN_VAL_NAME, inputDlg.GetValue(TURN_VAL_NAME))
	newComp.SetValue(RESISTANCE_VAL_NAME, inputDlg.GetValue(RESISTANCE_VAL_NAME))
	newComp.SetValue(LEAKAGE_INDUCTANCE_VAL_NAME, inputDlg.GetValue(LEAKAGE_INDUCTANCE_VAL_NAME))
	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 Conductors to FEM Coils"
	message = "This script will replace all FEM conductors with FEM coils
" message = message + "
" + "-Note that FEM Conductors inside macro circuits will not be replaced." message = message + "
" + "-For FEM Conductors that are set using a inflow and outflow face in a 3D study, the FEM coil will only have the inflow face set." message = message + "
" + "-Also, conductor groups will be removed." message_jp = "
" + "
" + "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()

Download Python source code

ファイルご利用の注意点

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