Cats2D Multiphysics > Overview > Macro recorder

Cats2D macro recorder/player

Cats2D has a macro recorder/player that allows the user to record any series of actions selected in the interactive menus for later playback. After the macro recorder is turned on, menu choices and dialog responses given by the user are recorded to text file until the recorder is turned off. The user is offered several ways to enter responses during recording that make it possible to construct sophisticated macros for automating repetitive tasks.

While recording a macro the user may specify a menu choice by its numeric ID as normally done, but alternatively can enter enough letters from the menu label to uniquely identify it. For example the user might enter "Stream", or just "St" when selecting a streamline plot. This makes it easier to understand the text file saved by the macro recorder should the user wish to manually edit the macro file later to alter its behavior.

Dialog responses may be entered explicitly, for example the user may specify fixed numbers for maximum and minimum contour values that will be used every time the macro is played. A useful alternative is to enter carriage return alone, which causes the default values to be applied, in this case the global maximum and minimum values of the current solution. Then each time the macro is played for a different solution, contour plots will be created based on the global limits for that solution.

Sometimes we do not know in advance the desired response to a dialog when a macro is played. For example we often want to enter a different filename each time we play a macro to create a contour or line plot. This can be done by preceding the filename by the hashmark # when recording the macro. When the macro is played back, the code will prompt the user to enter the desired filename. We can precede any menu choice or dialog response by # during recording to enable user intervention during playback.

Macros can call macros. Suppose we create a macro named Streamline to plot streamlines, and another macro named Temperature to plot temperature contours, and later realize that we want to create these plots for several different solutions we have saved. We can record a macro that reads a solution (preceding the ID with # to allow user intervention during playback), then calls the Streamline and Temperature macros.

Note that we can accomplish something similar to the previous example by using command line flags. Executing the code thusly:

cats2d -b -dSolutionDirectory -n10,100,10 -mStreamline -mTemperature

will cause it to play the macros for solutions with IDs 10, 20,..., 100 in SolutionDirectory. Using this approach avoids the need to enter the solution ID manually, which is advantageous when processing a large number of solutions with fixed stride between IDs. To make sure each plot file is given a unique name, we might enter the filenames preceded by # when recording the macros, but this creates a need for manual intervention that defeats the purpose of batch processing. Instead we should use the auto-filename feature of the Cats2D post-processor to create a sequence of unique numbered filenames for each plot file.