[S8339] Script to add cases with different current amplitude values and output the results of each case to a csv file

 

The following is an example script that adds cases with different current amplitude values and outputs the results of each case to a csv file.

app = designer.GetApplication()

# Set Current Study

app.SetCurrentStudy(0)

# Adding parameter variables

app.GetModel(0).GetStudy(0).GetDesignTable().AddParameterVariableName(u"CS1 (3PhaseCurrentSource): Amplitude")

# Add a case

app.GetModel(0).GetStudy(0).GetDesignTable().AddCases(2)

# Set case value

app.GetModel(0).GetStudy(0).GetDesignTable().SetValue(1, 0, 4)

app.GetModel(0).GetStudy(0).GetDesignTable().SetValue(2, 0, 8)

# Run analysis for all cases

app.GetModel(0).GetStudy(0).RunAllCases()

# Use a for statement to display each case and output the results

for i in range(3):

   caseID = int(i)+1

# Specify which cases to display

   app.View().SetCurrentCase(caseID)

# Export CSV file

   app.GetModel(0).GetStudy(0).GetResultTable().GetData("Torque").WriteTable(u"D:/torque" + str(caseID) + u".csv","Time")

How to use script file

Use the JMAG Script Library after reading and agreeing to the following terms of use.