Callback and State API
State is managed somewhat simply but in a limited fashion. All API methods take a final dictionary argument. This dictionary is limited to using string keys and number or string values. Within this limitation, simply add new keys, read old keys, clear the dictionary, etc. and it will be persisted across functions calls and 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 API methods use a subset of the following arguments
IterationNumber |
An integer representing the current iteration. This always starts from 1. |
ContainerList |
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, identify them. |
Container |
A single container that is being processed. This is a DataContainerReference. |
State |
A read/write python dictionary 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 the BeforeIteration 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. The "Container" argument represents the container about to be refreshed.
- AfterContainerRefresh(IterationNumber, Container, ContainerList, State): Is called after each of the coupled containers is refreshed. The "Container" argument represents the container just refreshed.
- BeforeContainerUpdate(IterationNumber, Container, ContainerList, State): Is called before each of the coupled containers is Update (after a refresh). The "Container" argument represents the container about to be updated.
- AfterContainerUpdate(IterationNumber, Container, ContainerList, State): Is called after each of the coupled containers is updated. The "Container" argument represents the container just updated.
If the callback scripts use other files to send commands to various containers (vb, js, apdl, python, etc.), all of those files are best saved in the user_files directory. This allows you to use FBGetUserFilePath(str) to get the absolute path of the file and allows the files to be packaged with any created archive.
Utility Functions
FBSystemForContainer(container) |
system |
Given a container, returns the system it belongs to. |
FBSystemDisplayName(system) |
string |
Given a system, returns its display name on the schematic. |
FBSystemID(system) |
string |
Given a system, returns its ID. This is the same as the UniqueDirectory for the system. |
FBGetUserFilesPath(relativePath) |
|
Given a relative path located under the user_files directory, returns the absolute path of the file. |
Output/Debugging Functions
FBAddInfoMessage(string) |
Adds an info message to the WB message window. |
FBAddWarningMessage(string) |
Adds a warning message to the WB message window. |
FBAddErrorMessage(string) |
Adds an error message to the WB message window. |
FBMessageBox(string) |
Pops up a dialog box with the supplied string and an "OK" button. |