Application | PLAXIS 2D PLAXIS 3D |
Version | PLAXIS 2D 2023.1 and later PLAXIS 3D 2023.1 and later |
Date created | 16 April 2025 |
Date modified | 23 April 2025 |
Original author | Stefanos Papavasileiou - Technical Support Group |
Keywords | PLAXIS, Output, cross section, results, automation, Python, scripting, API, py, cookbook |
With the release of PLAXIS 2023.1, it is possible to retrieve results from a cross section created in the PLAXIS Output program.
In this example, you will see how you can set up a Python script, which will allow you to retrieve various results for a cross section. The provided Python files offer an example for PLAXIS 2D and PLAXIS 3D.
To begin with, we will need to make sure that the current open PLAXIS Output program is accessible as a Remote Scripting Server. This can be achieved by activating the Remote scripting server via the Expert menu in the Output program.
For more information on how to do this, follow the article about Using PLAXIS Remote scripting with the Python wrapper
The structure of the Python example is the following:
In the following section, you can read about the Python example with regards to defining the cross section, retrieving the results and saving these to a text file. For the purpose of this demonstrated example, the PLAXIS 3D program will be used and specifically the PLAXIS 3D Tutorial 02: Excavation in sand.
Before retrieving any results, you need to add the cross section and create a new plot, i.e., the cross section plot.
ini_plot = g_o.Plots[-1] cs_soil_plot = g_o.crosssectionplot(ini_plot, (0, 0, -8), (1, 0, -8), (0, 1, -8))
In order to retrieve the results from the cross section the getcrosssectionresults() command will be used.
phase = g_o.Phases[-1] # coordinates values_soil_X = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.Soil.X) values_soil_Y = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.Soil.Y) values_soil_Z = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.Soil.Z) # deformations values_soil_Utot = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.Soil.Utot) # stresses values_soil_SigxxE = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.Soil.SigxxE) values_soil_SigyyE = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.Soil.SigyyE)
For the specific results, which are available for the cross section only, you need to consider the g_o.ResultTypes.CrossSection object.
# specific cross section results values_soil_EffNormalStress = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.CrossSection.EffNormalStress) values_soil_VerticalShearStress = g_o.getcrosssectionresults(cs_soil_plot, phase, g_o.ResultTypes.CrossSection.VerticalShearStress)
Finally, after retrieving the results, a file (called "filename_soil") will be created, which will be saved as a normal text file (*.txt).
with open(filename_soil, "w") as file: for results in zip(values_soil_X, values_soil_Y, values_soil_Z, values_soil_Utot, values_soil_Ux, values_soil_Uy, values_soil_Uz, values_soil_SigxxE, values_soil_SigyyE, values_soil_SigzzE, values_soil_EffNormalStress, values_soil_VerticalShearStress): print('\t'.join(["{}".format(i) for i in results]), file=file)
Note that in this Python example, the specified path of the text file is provided at the beginning of the Python script.
filename_soil = r'D:\PLAXIS\soil_cross_section_results_3D.txt'
This script has been tested with PLAXIS 2D and 3D 2024.1 and Python 3.12.3.