Skip to main content
This Script Tip Friday is brought to you by Pernelle Marone-Hitz, Lead Application Engineer at Ansys. Pernelle’s tip today will cover how to efficiently combine MAPDL and Mechanical scripting. Many users have developed post-processing macros based on MAPDL command snippets in Mechanical. The usual workflow is to have the command snippet use MAPDL to extract result data and then write the results to an output text file. These scripts work fine but it is often hard to link the Mechanical model with the content of the exported file. In the example we’ll consider today, a model has several joints defined: and an APDL script has been used to extract the reaction forces and moments on these joints. (Note – other methods could have been used for extracting these results, but this is not the point of this script tip). It is not easy to relate the joint’s name in Mechanical to the element number used by the MAPDL solver, which is what the MAPDL post-processing script is usually based on. To alleviate this problem, Mechanical automation scripting and MAPDL scripting can be combined. The following Mechanical Automation script will browse through the connections’ folder and insert an APDL command snippet under each joint, provided that it is not in suppressed stat
Each command snippet is automatically populated with a few lines of MAPDL code to store the joint element number and the joint’s name.
Then, for the MAPDL post-processing macro, it is easy to loop over all the joints as their total number has been evaluated in the Mechanical automation script and stored in variable nb_joints. The Mechanical name of each joint is known and can be used in the MAPDL macro, and more specifically can be written in the exported file. As an example, the MAPDL script below will extract reaction forces and moments on the “I” joint node for each joint in the model:
The outputfile.txt file is written in the solver’s file directory: and can be opened in any text editor: