Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
  • Welcome
  • Products
  • Support
  • About
  • More
  • Cancel
PLAXIS | SOILVISION
  • Product Communities
  • More
PLAXIS | SOILVISION
PLAXIS | SOILVISION Wiki Automatic line cross-section chart generation using Python
    • Sign in
    • -Geotechnical Analysis Wiki
      • +Geotechnical SELECT Entitlements [GSE]
      • -PLAXIS
        • +Software and License - PLAXIS
        • +Documentation - PLAXIS
        • -API / Python scripting - PLAXIS
          • Access to Staged Construction settings using Python
          • Adding functionality to PLAXIS Calculation Manager: pre- and post-processing
          • Automatic line cross-section chart generation using Python
          • Automatically generated cross-sections of embankments
          • Changing the material colour using Python scripting
          • Combined plate results in one chart using Python
          • Create custom connection with selection API
          • Export and format plots from PLAXIS Output using Python
          • How to create a tunnel using Python
          • How to get a load - displacement curve using Scripting interface
          • How to install additional Python modules in PLAXIS
          • How to open and close a PLAXIS project with Python
          • How to retrieve results from PLAXIS Output by the node number
          • Identify Python commands from Plaxis command line
          • Material lists in PLAXIS – Python
          • Material Property changes for Python scripting
          • Output scripting example: create curve data
          • Output scripting example: get anchor force
          • Output scripting example: get heave of excavation bottom
          • Output scripting example: get maximum bending moment
          • Polycurves to Polygons in PLAXIS 2D using Python
          • Receive instant notifications for finished calculations on your phone
          • Remove invalid custom connections for PLAXIS 3D
          • Retrieve coordinates of a Polygon in PLAXIS 2D using Python
          • Retrieving soil layer info from boreholes using Python
          • Scripting reference and how to use it
          • Selection API for PLAXIS Input
          • Soil layer material assignment using Python
          • Tunnel advancement script for PLAXIS 3D
          • User defined Python script (3D): Extract displacements by coordinates
        • +Known issues - PLAXIS
        • +Models - PLAXIS
        • +Tips and Tricks
        • +Publications
        • +Videos - PLAXIS
      • +PLAXIS LE
      • +PLAXIS Monopile Designer
      • +SOILVISION
      • +Subscription Entitlement Service
    • +Working from home with PLAXIS
    • +Working from home with PLAXIS LE

     
     Questions about this article, topic, or product? Click here. 

    Automatic line cross-section chart generation using Python

    Application PLAXIS 2D
    PLAXIS 3D
    Version PLAXIS 2D 2017
    PLAXIS 3D 2016
    Date created 05 December 2017
    Date modified 05 December 2017

    Versions: 3D 2016 and later, 2D 2017 and later

    Description

    In this article, a simple example is provided on how to create a line cross-section by using the Remote Scripting feature in the Plaxis Output program. In addition, the matplotlib module is used to create a chart from the results of the line cross-section. This Python script retrieves the results for total displacements of soil elements.

    Python solution

    By using the Remote Scripting Server in the Plaxis Output program, we can create a Python script to automatically retrieve the results for a specified line cross-section. The attached script requires the user to define the following variables:

    • sample_count: this is the number of intervals used for the line cross-section
    • start: this is the starting point of the line cross-section
    • end: this is the endpoint of the line cross-section

    The Python script will then:

    • gather the results for total displacements of soil using the getsingleresult command
    • report an error in case the position lies outside the generated mesh
    • create and display a chart with the results

    Boilerplate code

    In order to use the Python script, you must make sure that your Python script can communicate with the PLAXIS application. For more information on the boilerplate code please check the following article on Using PLAXIS Remote scripting with the Python wrapper.

    Note that the Python script uses the g_o variable. This variable is bound to the global object of the current open Plaxis model in Output.

    Modules used

    The Python script requires the following modules:

    • The plxscripting module to interact with PLAXIS 3D Output
    • The matplotlib module to create a chart

    All modules are part of the standard PLAXIS 3D 2016 (and later) installation that includes a full Python 3.4.x distribution.

    Python code

    from matplotlib import pyplot
    
    sample_count = 16
    start = (2.0, 4.0, 0.0)
    end = (2.0, 0.0, 0.0)
    # assumes that start and end contain floats
    
    
    def gather_results():
        step = [(e - s) / (sample_count - 1) for e, s in zip(end, start)]
        results = []
        for i in range(sample_count):
            position = (start[0] + i * step[0],
                        start[1] + i * step[1],
                        start[2] + i * step[2])
            result_string = g_o.getsingleresult(g_o.Phases[-1],
                                                g_o.ResultTypes.Soil.Utot,
                                                position)
            # check if position lies outside the mesh
            if result_string == "not found":
                raise Exception("Used getsingleresult for point outside mesh.")
    
            results.append(float(result_string))
        return results
    
    results = gather_results()
    
    
    def output_results():
        pyplot.plot(range(len(results)), results, 'r')
        pyplot.grid(True)
        pyplot.show()
    
    output_results()
    

    Version

    This script has been made for PLAXIS 3D 2016.02 using Python 3.4.x

    Notes

    The current Python script can be also used for making a 2D line cross-section. The 2D version of the Python script requires the following changes:

    • start and end values: should use two coordinates (x, y)
    • position variable in function: requires two parameters for each coordinate

    Disclaimer

    This Python script is made available as a service to PLAXIS users and can only be used in combination with a Bentley Geotechnical SELECT Entitlement [GSE] (former PLAXIS-VIP) license.
    You use this Python script at your own responsibility and you are solely responsible for its results and the use thereof. Plaxis does not accept any responsibility nor liability for the use of this Python script nor do we provide support on its use.

     

    See also

    Using PLAXIS Remote scripting with the Python wrapper

    [Tips and Tricks]


    Identify Python commands from Plaxis command line

    [Python Scripts]

    • PLAXIS 3D
    • python
    • API
    • py cookbook
    • Automation
    • Scripting
    • PLAXIS
    • Remote scripting
    • cookbook
    • python cookbook
    • PLAXIS 2D
    • Share
    • History
    • More
    • Cancel
    • Micha van der Sloot Created by Bentley Colleague Micha van der Sloot
    • When: Wed, Dec 18 2019 9:33 AM
    • Stefanos Papavasileiou Last revision by Bentley Colleague Stefanos Papavasileiou
    • When: Tue, Feb 15 2022 6:11 AM
    • Revisions: 3
    • Comments: 0
    Recommended
    Related
    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2021 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies