app= designer.GetApplication()
study=app.GetCurrentStudy()
study.DeleteResult()
defget_parameters_from_dialog(app):
dialog=app.CreateDialogBox()
setup_param_input_dialog(app, dialog)
returndialog
defsetup_param_input_dialog(app, dialog):
dialogTitle="JMAG-Designer: Create Calculation Case Setting"
label_1="Case set File:"
label_2="Number of Poles:"
dialog.SetTitle(dialogTitle)
dialog.AddLabel(label_1, 0, 1)
dialog.AddSaveFilename(open_file, "", "", "*.csv", 1, 1)
dialog.AddLabel(label_2, 0, 1)
dialog.AddInteger(Num_poles, "", 4, 1, 1)
defCreate_parameter(study,ploe_num):
table=study.GetDesignTable()
new_p={'Speed':'3000','poles':str(ploe_num),'Ia':'300','phase':'40','step_angle':'0.5'}
p_num=table.NumParameters()
old_p=[]
foriinrange(p_num):
old_p.append(table.GetEquation(i).GetName())
foriinrange(len(new_p)):
p_name=list(new_p.keys())[i]
ifp_namenotinold_p:
table.AddEquation(p_name)
p_index=table.GetParameterOrder(p_name)
table.GetEquation(p_index).SetType(0)
table.GetEquation(p_index).SetExpression(new_p[p_name])
foriinrange(study.NumConditions()):
ifstudy.GetCondition(i).GetType()=='Motion: Rotation':
study.GetCondition(i).SetValue('AngularVelocity','Speed')
study.GetCircuit().GetComponent('CS1').SetValue('Amplitude', 'Ia')
study.GetCircuit().GetComponent('CS1').SetValue('Frequency', 'poles/2*Speed/60')
study.GetCircuit().GetComponent('CS1').SetValue('PhaseU', 'phase')
study.GetStep().SetValue('StepType', 1)
study.GetStep().SetValue('Step', '720/poles/step_angle+1')
study.GetStep().SetValue('EndPoint', '2/poles/(Speed/60)')
study.GetStep().SetValue('StepDivision', '720/poles/step_angle')
defCreate_case(study,file,poles):
Create_parameter(study,poles)
file=open(file,'r')
lines=file.readlines()
num_case=study.GetDesignTable().NumCases()
case_order=num_case-1
forlineinlines[1:]:
case_order+=1
data=line.split(',')
r_v=data[0]
I_am=data[1]
phase=data[2]
study.GetDesignTable().AddCase()
r_v_index=study.GetDesignTable().GetParameterOrder('Speed')
study.GetDesignTable().SetValue(case_order, r_v_index, r_v)
Ia_index=study.GetDesignTable().GetParameterOrder('Ia')
study.GetDesignTable().SetValue(case_order, Ia_index, I_am)
phase_index=study.GetDesignTable().GetParameterOrder('phase')
study.GetDesignTable().SetValue(case_order, phase_index, phase)
poles_index=study.GetDesignTable().GetParameterOrder('poles')
study.GetDesignTable().SetValue(case_order, poles_index, poles)
defmain_create_case(study):
parameters=get_parameters_from_dialog(app)
ret=parameters.Show()
file=parameters.GetValue(open_file)
poles=parameters.GetValue(Num_poles)
ifret==1:
Create_case(study,file,poles)
else:
pass
open_file='open_file'
Num_poles='num_poles'
main_create_case(study)
夜雨聆风