Output scripting example: create curve data


Application PLAXIS 2D
PLAXIS 3D
Version PLAXIS 2D
PLAXIS 3D
Date created 06 May 2015
Date modified 07 November 2024

Since PLAXIS 2D 2015 and PLAXIS 3D AE, the Output program can also be accessed via REST HTTP / Remote Scripting API in order to retrieve calculation result data via a scripting interface.

Retrieving curve data is one of the possible options for data retrieval. In this example, we will retrieve the results and store these in a text file.

First, 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

Now we can retrieve the data. For this, we will use the command getcurveresults(). Since this command will only return one result value, the script will need to access each step id of the desired phases.

In the example below, the Python script stores a table in a file, and it will store the following columns, using the phase order as specified in the parameter phaseorder:

Note: If you are dealing with a post-calc selected curve point, you will need to store all steps during your calculation, otherwise it will not be possible to retrieve the time value for any of the unsaved steps. For the pre-calc selected curve points all step results are stored automatically. For more information on the curve points, check the article Selecting points for curves.

def gettable_time_vs_uy(filename=None, phaseorder=None):
    # init data for lists
    stepids = []
    uyAs = []
    uyBs = []
    times = []
    phasenames = []

    # look into all phases, all steps:
    for phase in phaseorder:
        for step in phase.Steps.value:
            phasenames.append(phase.Name.value)
            stepids.append(int(step.Name.value.replace("Step_", "")))
            uyAs.append(g_o.getcurveresults(g_o.Nodes[0],
                                            step,
                                            g_o.ResultTypes.Soil.Uy))
            uyBs.append(g_o.getcurveresults(g_o.Nodes[1],
                                            step,
                                            g_o.ResultTypes.Soil.Uy))
            # make sure step info on time is available, then add it:
            timevalue = "-"
            if hasattr(step, 'Reached'):
                if hasattr(step.Reached, 'Time'):
                    timevalue = step.Reached.Time.value

            times.append(timevalue)

    if filename:
        with open(filename, "w") as file:
            file.writelines(["{}\t{}\t{}\t{}\t{}\n".format(ph, nr, t, uyA, uyB)
                             for ph, nr, t, uyA, uyB in zip(phasenames,
                                                            stepids,
                                                            times,
                                                            uyAs,
                                                            uyBs)])

Now we can make a call to this function in order to save a text file with this data for phases Phase_1 and Phase_2:

gettable_time_vs_uy(filename= r'C:\data\project_curvedata.txt', 
                    phaseorder = [g_o.Phase_1, g_o.Phase_2])

This data can then easily be used in spreadsheet programs to easily create charts or do other sorts of post-processing.

Notes

Version

This Python script runs with PLAXIS 2D CONNECT Edition v20 using Python 3.7.x.
The script was originally written for PLAXIS 2D 2017.00 using Python 3.4.x.

See also