AmesimKnowledge

Tutorial

Getting variable values

API getting variable values

In the FlatTwin system, we are interested in visualizing piston displacement. To achieve this, we want to plot the x1@mass_friction1port and x1@mass_friction1port_2 variables.

Note

We will use the pylab module provided with Simcenter Amesim to plot these variable values.

You must import the API pylab

API
scipy

pylab

scipy
scipy and pylab modules using the import command:

Copy

# Import scipy and pylab modules
import scipy
import pylab

Look at the code below.

Copy

# Get & plot values
print ('Plotting "x1@left_piston_alias.mass_friction1port" and "x1@right_piston_alias.mass_friction1port_2"...')

# get variable values
res_1 = AMEGetVariableValues('x1@left_piston_alias.mass_friction1port')
res_2 = AMEGetVariableValues('x1@right_piston_alias.mass_friction1port_2')

# Format values
x_1 = scipy.array(res_1)
x_2 =scipy.array(res_2)
# get variable title (these two variables have the same title)
variable_title = AMEGetVariableInfos('x1@left_piston_alias.mass_friction1port')[2]

# Plot variables
pylab.plot(x_1[:,0], x_1[:,1], label='x1@left_piston_alias.mass_friction1')
pylab.plot(x_2[:,0], x_2[:,1], label='x1@right_piston_alias.mass_friction1_2')
pylab.legend(loc='upper left')
pylab.xlabel('Time')
pylab.ylabel(variable_title)
pylab.grid(True)
print ('Close the plot to continue...')
pylab.show()

Add the code to your script and launch it. The selected variables are plotted:

Figure 21: The plot

When you close the plot, the script terminates, and your FlatTwin.ame system is complete.

Source: https://docs.sw.siemens.com/en-US/doc/254352342/PL20250521841123434.amesim_collection.Circuit_API/Getting_variable_values · retrieved 2026-07-17