AmesimKnowledge

Tutorial

Using Iterators

Iterators are useful when we want, for example, to get a full set of information about a model’s contents without writing too many lines of code.

In the example below, we open the DigitalSignal.ame demo model and we get the full set of components and lines stored in this model.

Furthermore, while retrieving components and lines, we get the full set of parameters and variables contained in each model element.

Look at the code below. It uses the most common iteration functions: AMECreateCompLineIteration and AMECreateParVarIteration.

Copy

from ame_apy import *
AMEInitAPI()
AMEOpenAmeFile("DigitalSignal.ame")
for compline in AMECreateCompLineIteration(ame_compline_all):
   if AMEIsComponent(compline):
      print("")
      print ("Component:", AMECopyAliasPath(compline))
   else:
      print ("")
      print ("Line:", AMECopyAliasPath(compline))
   for parvar in AMECreateParVarIteration(compline, ame_parvar_all):
      if AMEIsParameter(parvar):
         print (" Parameter:", AMECopyDataPath(parvar), ("\t[%s]" % 
         AMEGetParameterInfos(parvar)[1]), 
         ("\t[%s]" % AMEGetParameterInfos(parvar)[2]))
      else:
         print (" Variable:", AMECopyDataPath(parvar), ("\t[%s]" % 
         AMEGetVariableInfos(parvar)[2]))
AMECloseCircuit()
print ("")
AMECloseAPI()

Add the code to a new script. Make sure that the DigitalSignal.ame model is located near your script and launch the script. The result is as follows:

Here we have retrieved each component or line, and for each component or line we have retrieved the list of parameters and variables that it includes.

For each parameter and variable, we have displayed its title, its name, and its unit in one line.

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