Exporting relevant Output plots into images for efficient results evaluation using Python


Application PLAXIS 2D
Version 2024.3 and later
Date created 27 June 2025
Date modified 27 June 2025
Original author Wai Liong Lai - Technical Support Group
Keywords PLAXIS 2D, Python, Output, Export, Plots, Failure, 

Introduction

When performing a finite element calculation, PLAXIS will attempt to solve a series of non-linear equations to find a solution that is in equilibrium. In some cases, this final equilibrium might not be reached – in other words, the calculation did not converge, and PLAXIS will display an error code. These error codes would give a general indication of what went wrong or what to do, and they can be found in the Reference Manual. Certain error codes (most commonly Error 101 and 103) suggest reviewing the calculation results in Output to diagnose the issue.

For a better understanding of why equilibrium has not been reached, the following PLAXIS Output results should be inspected:

While these results can be manually reviewed through the program’s interactive graphical user interface, a more efficient and scalable approach is to use a Python script that automates the extraction of result sets. This script can save the results as images in a designated, easily accessible folder – streamlining the process and reducing manual effort.

 

Extracting the desired plots from Output using Python

The Python script is structured into several functional parts:

 

from plxscripting.easy import *
localhostport = 10001
s_o, g_o = new_server('localhost', localhostport, password='YOUR_PASSWORD')

import os
import tkinter as tk
from tkinter import simpledialog

ROOT = tk.Tk()
ROOT.withdraw()


# Ask for the construction phase
def ask_phase_name():
    while True:
        phasename = simpledialog.askstring(title="Export Failure Inspection Plots",
                                  prompt="Type the construction phase number (e.g. Phase_1 or 1):")
        phasenr = None
        try:
            if phasename == str(int(phasename)):
                phasenr = phasename
        except:
            phasenr = None

        for phase in g_o.Phases[:]:
            if phase.Name.value.lower() == phasename.lower():
                return phase
            if phasenr is not None:
                if phase.Name.value.lower() == "Phase_{}".format(phasenr).lower():
                    return phase


# list of results to print
resultslist = [g_o.ResultTypes.Soil.DeformedMesh,
               g_o.ResultTypes.Soil.Utot,
               g_o.ResultTypes.Soil.dUtot,
               g_o.ResultTypes.Soil.TotalDeviatoricStrain,
               g_o.ResultTypes.Soil.IncrementalDeviatoricStrain,
               g_o.ResultTypes.Soil.PlasticPoint,
               g_o.ResultTypes.Soil.PExcess]

resultsname = ["DeformedMesh",
               "Utot",
               "dUtot",
               "TotalDeviatoricStrain",
               "IncrementalDeviatoricStrain",
               "PlasticPoint",
               "PExcess"]

# Retrieve the project name
project_path_dirname = os.path.dirname(str(g_o.GeneralInfo.Filename))

# Specify the folder name
folder_name = "Failure_Plots"

# Create the folder
os.makedirs(os.path.join(project_path_dirname, folder_name), exist_ok=True)

# Print a success message
print(f"Folder '{folder_name}' created in '{project_path_dirname}'")

# Create a folder in the same directory as the project to save the plots
folder_location = os.path.join(project_path_dirname, folder_name)


# Main 
phase = ask_phase_name()      
g_o.Plots[-1].Phase = phase

for i in range(len(resultslist)):
    g_o.Plots[-1].ResultType = resultslist[i]
    export_path = os.path.join(folder_location, f"{phase.Name.value}_{resultsname[i]}_results.png")   
    g_o.Plots[-1].export(export_path, 1920, 1080)

 

Improving the functionality/customising the Python script

As mentioned previously, it is possible to include more result types to be extracted into the list. The full list of the result commands can be found in the ‘Output objects reference’ (in the program, go to the Help tab > Command Reference).

It is also possible to include other visualisation commands into the Python script to improve the legibility of the extracted results, like adjusting the legend of the plots, showing and hiding different elements, zooming, or changing the viewpoints (PLAXIS 3D only). These commands can be individually included in the script to suit each project, as explained in Export and format plots from PLAXIS Output using Python.

The use of this script is not limited only to troubleshooting calculation errors – it can also be used to streamline the extraction of results across multiple calculations, making it an ideal solution for projects with large datasets or repetitive tasks.

 

See also