Callback and State API
State is managed in a limited fashion. All the API methods take a final dictionary argument. This dictionary is limited to using string keys and number or string values. Within this limitation, add new keys, read old keys, clear the dictionary, etc., and it will be persisted across functions calls and even across Updates. When the Iterations Completed property is rest, the dictionary is also cleared out.
It is advisable for the callback script to initialize the dictionary at Iteration 1.
All the API methods use a subset of the following arguments:
|
An integer representing the current iteration. This always starts from 1. |
|
A Python list of containers (DataContainerReference). This is the entire list of the coupled containers managed by the Feedback Iterator. You typically loop through them and using the utility methods listed below, identities them. |
|
A single container that is being processed. This is a DataContainerReference. |
|
A read/write Python dictionary that is used to maintain state across function calls and iterations. |
Only return values from BeforeIterationEx
are processed.
Returns from all other functions are discarded.
BeforeIteration(IterationNumber, ContainerList, State)
: This method is called before each iteration. Ideally used to initialize the state dictionary, open editors as required, or initialize setups as needed for each iteration.BeforeIterationEx(IterationNumber, ContainerList, State)
: Similar to theBeforeIteration
method except that this allows you to control the number of iterations via the return value.
- Return:
“more”
to request one more iteration - Return
“last”
to indicate that this is the last iteration - Any other return (including none) will be treated
as a return of
“last”
and terminate iterations.
AfterIteration(IterationNumber, ContainerList, State)
: This method is called after each iteration. This can be used to copy result files over, check results, implement any possible convergence calculations, logging of results, etc.BeforeContainerRefresh(IterationNumber, Container, ContainerList, State)
: Is called before each of the coupled containers is refreshed. TheContainer
argument represents the container about to be refreshed.AfterContainerRefresh(IterationNumber, Container, ContainerList, State)
: Is called after each of the coupled containers is refreshed. TheContainer
argument represents the container just refreshed.BeforeContainerUpdate(IterationNumber, Container, ContainerList, State)
: Is called before each of the coupled containers is Update (after a refresh). TheContainer
argument represents the container about to be updated.AfterContainerUpdate(IterationNumber, Container, ContainerList, State)
: Is called after each of the coupled containers is updated. TheContainer
argument represents the container just updated.
If the callback scripts uses other files to send commands
to various containers (vb, js, apdl, python, etc.), all of those files
are best saved under the user_files directory. This allows you to use
the FBGetUserFilePath(str)
to get the absolute path of the file and allows
the files to be packaged with any created archive.
Utility Functions
|
system |
Given a container, returns the system it belongs to. |
|
string |
Given a system, returns its display name on the schematic. |
|
string |
Given a system, returns its ID.
This is the same as the |
|
Given a relative path located under the user_files directory, say "hello.py", this returns the absolute path of the file. |
Output/Debugging Functions
|
Adds an info message to the WB message window. |
|
Adds a warning message to the WB message window. |
|
Adds an error message to the WB message window. |
|
Pops up a dialog with the supplied string with an OK button. |