Skip to main content

PLAXIS

PLAXIS has a Python API that is distributed in a Python installer. The API can be used to build-up PLAXIS models and process results, integrating the PLAXIS workflow within your VIKTOR app. For more information on the PLAXIS API, see the website.

note

A 'Bentley Geotechnical SELECT Entitlement' (previously 'PLAXIS-vip') license is required

To integrate PLAXIS in your application, the following is needed:

  • A Generic worker
  • A server on which PLAXIS is installed (with the correct licensing)

From within the VIKTOR app, the Python script is sent, via the generic worker, to the server. After the analysis, the generic worker sends back the specified files to the app, after which the developer can process the results (visualize, download, etc.). In the following code snippet two files are sent to the worker: run_plaxis.py and input.json. For additional ideas on how to pass parameters to PLAXIS have a look at the PLAXIS sample application.

from viktor.external.generic import GenericAnalysis# Generate the input file(s)files = [    ('run_plaxis.py', BytesIO(b'file_content_of_run_plaxis.py')),    ('input.json', BytesIO(b'{parameter_a: 1, parameter_b: 2}'))]# Run the analysis and obtain the output filegeneric_analysis = GenericAnalysis(files=files, executable_key="plaxis", output_filenames=["output.txt"])generic_analysis.execute(timeout=60)output_file = generic_analysis.get_output_file("output.txt")
caution

GenericAnalysis.execute needs to be mocked within the context of (automated) testing.

The file run_plaxis.py and the other file represented as bytes is then sent to the Python distribution PLAXIS is set to work with. You can specify which Python distribution PLAXIS should use, in the "Using a custom Python distribution" section.

The executable_key in the example above refers to the "plaxis" command. This command should also be specified in the configuration file on the server, located in the same directory as the worker:

config.yaml

executables:
plaxis:
path: 'C:\path\to\python.exe'
arguments:
- 'C:\scripts\run_plaxis.py'
workingDirectoryPath: 'C:\scripts'
maxParallelProcesses: 1 # must be one, please do not change

run_plaxis.py

The Python script that is sent to the worker should consist of the following parts:

  • Starting of the PLAXIS remote scripting service
  • Code to build-up the PLAXIS model and read-out the desired results
  • Creation of output files in the working directory of the worker, to be returned to the app
  • Close the PLAXIS application

Starting of the PLAXIS remote scripting service can be done as follows:

import subprocess, timePLAXIS_PATH = r'C:\Program Files\Bentley\Geotechnical\PLAXIS 2D CONNECT Edition V20\\Plaxis2DXInput.exe'  # Specify PLAXIS path on server.PORT_I = 10000  # Define an input port number.PORT_O = 10001  # Define an output port number.PASSWORD = 'secret'  # Define a password.subprocess.Popen([PLAXIS_PATH, f'--AppServerPassword={PASSWORD}', f'--AppServerPort={PORT}'])  # Start the PLAXIS remote scripting service.time.sleep(30)  # Wait for PLAXIS to boot before sending commands to the scripting service.# Start the scripting server.global g_i, s_is_i, g_i = new_server('localhost', PORT_I, password=PASSWORD)s_o, g_o = new_server('localhost', PORT_O, password=PASSWORD)# Execute code....# Extract required data and write files to working directory....# Close the applicationg_o.close()  # Close the output windowg_i.kill()  # Close the input window
caution

The resulting files can be very large. Consider sending back files to the app with only the relevant information, by filtering out unnecessary results, to reduce in size. An example can be found in the sample application