PLAXIS AUTOMATION SERIES
Step-by-step information towards automation
PLAXIS is a Finite Aspect modelling software program that geotechnical engineers will certainly come throughout at a sure level of their careers. Modelling advanced geotechnical issues in a PLAXIS will be difficult and represents time-consuming modelling work typically involving repetitive duties.
As an engineer, we at all times need to automate the boring and engineer the superior.
On this context, programming, extra particularly Python, is the most effective obtainable device to automate repetitive duties.
Python has been round for a few years however solely lately get recognised by the bigger group due to its ease of use, giant extent of purposes and assist by enormous open-source communities. It’s a nice programming language for information science, workflow automation and internet growth.
PLAXIS has a well-developed Utility Programming Interface (API) which permits customers to function PLAXIS by way of programming. Extra particulars will be seen on the official Bentley web site.
Though the PLAXIS Python API has been developed for a very long time, there’s nonetheless an absence of thorough tips to introduce this system to geotechnical engineers.
This tutorial assumes readers have zero expertise in programming so I’ll present how you can arrange the programming surroundings from scratch.
Disclaimer
There have been loads of paid programs which educate engineers to make use of the built-in Python editor in PLAXIS which I agree is kind of well-developed. However I personally want to make use of my very own programming surroundings to write down scripts due to the next three causes:
- A well-developed Built-in Improvement Surroundings (IDE) is extra user-friendly for coding because it picks up improper syntaxes and identifies bugs, which is essential for learners.
- Constructed-in Python editor has much less flexibility to import user-developed modules. Sooner or later when you’ve extra programming expertise, you can find that loads of time we have to separate out the features we write as a module which makes our script much less busy. This may be effectively managed in IDE.
- We don’t need to maintain the scripts to ourselves however to share amongst colleagues. IDE gives good integration with code-sharing platforms corresponding to GitHub, GitLab and so forth.
The last word purpose of this tutorial is to point out you how you can use Python script to create your first structural factor in PLAXIS 2D. This may be accomplished with the next 4 steps.
- Set up Built-in Improvement Surroundings (IDE)
- Activate PLAXIS Surroundings
- Hook up with PLAXIS API
- Create first plate factor
Lastly, this tutorial assumes readers are utilizing Home windows OS and have PLAXIS 2D V22 put in. So let’s get began!
IDE is a software program software which gives complete services for programming, often consisting of supply code editor, construct automation instruments and debugger.
There are numerous choices for IDE, corresponding to Visible Studio Code (VS Code), PyCharm, Jupyter Pocket book and so forth, which haven’t any distinction in performance and are fully as much as customers’ desire for the selection of IDE. This instruction demonstrates the set up of VS Code.
Set up Visible Studio Code (VS Code) with the next instruction:
Obtain the most recent VS code for Home windows: https://code.visualstudio.com/obtain
Observe the set up wizard, and test the choices as proven under.
As soon as put in, open VS Code on Desktop. You will note the next interface.
Add your work folder in Explorer by proper clicking Explorer -> Add Folder to Office…
You might have now bought VS code set-up and is able to begin coding!
As soon as your digital surroundings and IDE are arrange, you can begin writing Python script inside IDE.
To write down a Python script, it is best to observe the method under:
- Open IDE terminal
- Direct to your most well-liked work folder (in terminal)
- Activate PLAXIS Python Surroundings
- Create .py file within the folder
Open IDE terminal
Click on the “warning” icons within the backside menu bar:
You will note the Shell window comes up:
Head to “Terminal” tab within the high menu bar as indicated. You must see that you’re within the work folder.
Direct to your most well-liked work folder
If it’s not the proper work folder. You possibly can kind:
cd <your work folder path>
For instance, I’m presently at Present Initiatives folder and I need to find to 00_Digitalisation->01_Python-FE. The folder path is:
C:UsersphtsangDesktopCurrent_Projects 0_Digitalisation 1_Python-FE
In IDE terminal:
It ought to present the proper folder identify as proven above.
Activate PLAXIS Python Surroundings
To activate the PLAXIS Python surroundings, we might want to choose PLAXIS built-in python interpreter which incorporates all of the functionalities required to function PLAXIS. The python interpreter is routinely put in when PLAXIS is put in.
Location of the Python interpreter:
C:ProgramDataBentleyGeotechnicalPLAXIS Python Distribution V2pythonpython.exe
To pick a selected surroundings, use the Python: Choose Interpreter command from the Command Palette (Ctrl+Shift+P). Click on “Enter interpreter path…”, then browse the python.exe within the location talked about above.
Within the Terminal tab, choose Command Immediate within the drop down record as highlighted under.
You must see (PLAXIS) in entrance of the working listing if the surroundings is activated efficiently.
Create .py file within the folder
Click on the New file icon:
Create .py file as under:
Subsequent part we are going to begin connecting to the PLAXIS API.
I’ll first create an empty python script and name it “create_plate.py” as proven under.
After that, we write the code under to the python file. Three issues are doing right here:
- Import modules from PLAXIS Python surroundings. With the intention to function PLAXIS with Python script, we have to use the features (extra generally referred to as strategies by way of programming) developed by PLAXIS. The module we import known as “plxscripting.east”
- Open PLAXIS 2D desktop software. The trail of the Plaxis2DXInput.exe ought to be the identical as listed under if default set up path is adopted. If that’s not the case, merely change the trail to the proper listing. Port quantity and Password can keep as default however you’ll be able to choose any values you need.
- Begin the PLAXIS scripting server with the pre-defined port quantity and password.
from plxscripting.simple import *
import subprocess, timePLAXIS_PATH = r'C:Program FilesBentleyGeotechnicalPLAXIS 2D CONNECT Version V22Plaxis2DXInput.exe' # Specify PLAXIS path on server.
PORT_i = 10000 # Outline a port quantity.
PORT_o = 10001
PASSWORD = 'SxDBR<TYKRAX834~' # Outline a password (as much as person selection).
subprocess.Popen([PLAXIS_PATH, f'--AppServerPassword={PASSWORD}', f'--AppServerPort={PORT_i}'], shell=False) # Begin the PLAXIS distant scripting service.
time.sleep(5) # Look ahead to PLAXIS besides earlier than sending instructions to the scripting service.
# Begin the scripting server.
s_i, g_i = new_server('localhost', PORT_i, password=PASSWORD)
s_o, g_o = new_server('localhost', PORT_o, password=PASSWORD)
s_i.new()
g_i.gotostructures()
To check that the code above is working correctly, we are going to run “create_plate.py” within the terminal as proven under. Sort “python create_plate.py” and click on Enter.
(PLAXIS) C:UsersphtsangDesktopPLAXIS_V22Script>python create_plate.py
The PLAXIS 2D app ought to be opened routinely. If the server is configured accurately, it is best to see “SERVER ACTIVE” as proven under.
Now that we hook up with the PLAXIS API server, we will then create a plate factor in PLAXIS utilizing Python script.
On this a part of tutorial, we purpose to create a plate factor with constructive and damaging interfaces. Then we assign “Concrete” materials to the factor.
First, we outline the fabric identify and geometry. I plan to create a line from (-10,0) to (10,0). The sq. bracket [ ] known as record in python, which is a quite common information kind to retailer values. To entry the values saved in an inventory, it’s referred to as within the following syntax:
If I need to entry the coordinates of first level, I take advantage of
x coordinate = -10 = first_point[0]
y coordinate = 10 = first_point[1]
0 and 1 right here referred to as index which at all times begins from 0.
Then we create the fabric and assign it to the plate materials record. To create plate materials, the command “g_i.platemat()” is used. The code beneath is to assign the plate object to an inventory.
materials=['Concrete']
first_point=[-10,0]
second_point=[10,0]# Create materials
for i in vary(len(materials)):
g_i.platemat('Identification',materials[i])
platematerials = [mat for mat in g_i.Materials[:] if mat.TypeName.worth == 'PlateMat']
After that, we create plate factor with “g_i.plate()” based mostly on the pre-defined coordinates.
plate=g_i.plate(
(first_point[0],first_point[1]),
(second_point[0],second_point[1]),
)
plate1=plate[-1]
Then, create interfaces utilizing “g_i.posinterface()” and “g_i.neginterface()”.
plate2=plate[-2]
g_i.posinterface(plate2)
g_i.neginterface(plate2)
Lastly, set “Concrete” to the plate factor.
plate1.setmaterial(platematerials[0])
When you rerun the script, you will note the next is created in PLAXIS. As you see, the “Concrete” materials is created and assigned to the plate factor we created.
Congratulations! You might have simply created your first plate factor in PLAXIS utilizing Python!
After all, we regularly must create multiple structural factor in PLAXIS. On this part, we purpose to create 4 plate components which kind a rectangle with the next coordinates:
- (-10,0)
- (-10,10)
- (10,10)
- (10,0)
We have to first create an inventory (name it ‘df_plate’) which specifies the coordinates of every plate factor. The primary and second factors are saved as (x1,y1) and (x2,y2) respectively. Inside the record, I used a brand new information kind referred to as Dictionary which could be very generally utilized in Python. Extra on that within the subsequent tutorial.
df_plate=[{'x1':-10,'y1':0,'x2':10,'y2':0},{'x1':-10,'y1':10,'x2':-10,'y2':0},{'x1':-10,'y1':10,'x2':10,'y2':10},{'x1':10,'y1':10,'x2':10,'y2':0}]
Since this time we have to entry a number of components in an inventory, we are going to utilise an idea referred to as for loop. It permits us to loop by way of the weather and create factors in PLAXIS accordingly. This may be accomplished with the next code:
for i in vary(len(df_plate)):
plate=g_i.plate(
(df_plate[i]['x1'],df_plate[i]['y1']),
(df_plate[i]['x2'],df_plate[i]['y2']),
)
plate1=plate[-1]
Your remaining script ought to appear to be:
# Plate
#Materials identify and geometry
materials=['Concrete']df_plate=[{'x1':-10,'y1':0,'x2':10,'y2':0},{'x1':-10,'y1':10,'x2':-10,'y2':0},{'x1':-10,'y1':10,'x2':10,'y2':10},{'x1':10,'y1':10,'x2':10,'y2':0}]
# Create materials
for i in vary(len(materials)):
g_i.platemat('Identification',materials[i])
platematerials = [mat for mat in g_i.Materials[:] if mat.TypeName.worth == 'PlateMat']
#Create Plate
for i in vary(len(df_plate)):
plate=g_i.plate(
(df_plate[i]['x1'],df_plate[i]['y1']),
(df_plate[i]['x2'],df_plate[i]['y2']),
)
plate1=plate[-1]
#Create Interface
plate2=plate[-2]
g_i.posinterface(plate2)
g_i.neginterface(plate2)
#Set Materials
plate1.setmaterial(platematerials[0])
When you rerun the script, you will note the next is created in PLAXIS. Now, you’ll be able to create a number of components utilizing Python script.
That’s the tip of the primary tutorial on automating PLAXIS with Python. By now, it is best to have the ability to create structural components in PLAXIS utilizing Python script. Sooner or later, I’ll maintain posting tutorials on utilizing Python in PLAXIS. Greater than that, I’m additionally eager to share data on how you can use Python to automate boring workflow in engineering.
When you’re interested by listening to extra about Python, PLAXIS and workflow automation, be at liberty to observe my web page.