PLAXIS 2D + Python Scripting Tutorial 2

Drained/undrained embankment stability, mesh, phases, and safety analysis via the Remote Scripting API.

⬇️ PDF

1️⃣ Introduction

This tutorial demonstrates controlling PLAXIS 2D with Python via the Remote Scripting API, using a Jupyter-like step-by-step flow converted into a clean web page.

The scripting objects exposed by PLAXIS are:

  • s_i – Input server object (sends commands to PLAXIS Input).
  • g_i – Global Input object (materials, geometry, boreholes, mesh, etc.).
  • s_o and g_o – corresponding Output objects for post-processing.

The workflow covered here:

  • Connect ▶ Set project ▶ Create geometry ▶ Define/assign materials ▶ Mesh ▶ Phases ▶ Safety ▶ Results

2️⃣ Connect to PLAXIS Remote Scripting Servers

Ensure PLAXIS Input and Output are running the Remote Scripting Server on ports 10000 and 10001.

from plxscripting.easy import *

# ⚠️ Replace with your own password (keep it secure)
user_password = "your-password-here"

# Connect to PLAXIS Input (10000) and Output (10001)
s_i, g_i = new_server('localhost', 10000, password=user_password)
s_o, g_o = new_server('localhost', 10001, password=user_password)

Downstream cells assume successful connections; handle exceptions in production scripts.

3️⃣ Start a New Project & Save

Clear the model and save a new project file to persist the state regularly.

# Choose a project path (without extension)
filepath = r"C:\Users\<you>\Plaxis_playground\tutorials\tutorial_2"

# Reset and save
s_i.new()
g_i.save(filepath)

PLAXIS maintains many intermediate states; saving preserves your working state.

4️⃣ Project Properties & Computational Domain

Set metadata, model type, element type, and define the soil contour (domain extents).

# Project info
g_i.Project.Title.set("Lesson 2")
g_i.Project.Comments.set("Drained and undrained stability of an embankment")
g_i.Project.ModelType.set("plane strain")
g_i.Project.ElementType = "15-Noded"

# Soil contour rectangle: (x_min, y_min, x_max, y_max)
g_i.SoilContour.initializerectangular(0, -6, 50, 4)

5️⃣ Boreholes & Soil Layers

Create a reference borehole and define layer elevation and groundwater head.

# Borehole at x = 0
borehole_g = g_i.borehole(0)

# Soil layer boundary (top elevation)
boreholepolygon_g = g_i.soillayer(6)  # y = 6 (PLAXIS echoes as absolute y)
print(boreholepolygon_g.y.echo())

# Groundwater head
borehole_g.Head = 0
print(borehole_g.Head.echo())

The borehole controls layer topology and groundwater distribution across the domain.

6️⃣ Define Soil Materials (Hardening Soil)

Create drained/undrained materials and set properties using setproperties().

# Create materials
embankment_sand = g_i.soilmat("Identification","embankment sand", "SoilModel","hardening soil")
subgrade_clay = g_i.soilmat("Identification","subgrade clay", "SoilModel","hardening soil")
subgrade_clay_undrained = g_i.soilmat("Identification","subgrade clay undrained", "SoilModel","hardening soil")

# Property sets
sand_properties = [
    ("DrainageType","drained"), ("gammaUnsat",16), ("gammaSat",16),
    ("E50Ref",15000), ("EOedRef",15000), ("EURRef",45000),
    ("PowerM",0.5), ("cRef",3), ("phi",30), ("K0Determination","automatic"), ("OCR",1),
]
clay_properties = [
    ("DrainageType","drained"), ("gammaUnsat",13), ("gammaSat",13),
    ("E50Ref",5600), ("EOedRef",5000), ("EURRef",20000),
    ("PowerM",1), ("cRef",10), ("phi",25), ("K0Determination","automatic"), ("OCR",1.2),
]

# Apply properties and assign initial subgrade material
embankment_sand.setproperties(*sand_properties)
subgrade_clay.setproperties(*clay_properties)
subgrade_clay_undrained.setproperties(*clay_properties)
subgrade_clay_undrained.DrainageType = "undrained a"

# Assign to soil domain represented by the borehole polygon
boreholepolygon_g.Soil.Material = subgrade_clay

7️⃣ Create Embankment Geometry

Switch to Structures, define the embankment polygon, and assign embankment sand.

# Go to Structures mode
g_i.gotostructures()

# Embankment polygon and material assignment
embankment_polygon = g_i.polygon((14,0), (22,4), (24,4), (36,0))[0]
embankment_polygon.Soil.setproperties("Material", embankment_sand)

8️⃣ Mesh Generation & Monitoring Points

Generate a fine mesh and add a curve point near the slope toe in Output for displacement tracking.

# Mesh
g_i.gotomesh()
g_i.mesh(0.04)  # target element size

# Monitoring point in Output
g_i.selectmeshpoints()
g_o.addcurvepoint('node', g_o.Soil_1_1, (18, 0))
g_o.update()

9️⃣ Phases & Calculation

Create staged construction phases, activate the embankment, and run calculations.

# Staged Construction
g_i.gotostages()
phase0_s = g_i.InitialPhase

# New phases (drained and undrained scenarios)
phase1_s = g_i.phase(phase0_s)
phase2_s = g_i.phase(phase0_s)

# Re-acquire the polygon handle in Stages
embankment_g = g_i.Polygons[0]
embankment_g.activate(phase1_s, phase2_s)

# Switch subgrade to undrained for phase 2
g_i.Soils[1].Material.set(phase2_s, subgrade_clay_undrained)

# Run calculation and save
g_i.calculate()
g_i.save(filepath)

🔟 Factor of Safety (Phi–c reduction)

Clone phases and set DeformCalcType to safety for drained and undrained cases.

# Create FoS phases
phase3_s = g_i.phase(phase1_s)  # drained base
phase4_s = g_i.phase(phase2_s)  # undrained base

# Identify and set to Safety
phase3_s.Identification = "FoS of drained case"
phase3_s.DeformCalcType = "safety"
phase4_s.Identification = "FoS of undrained case"
phase4_s.DeformCalcType = "safety"

# Calculate both
g_i.calculate()

1️⃣1️⃣ Extracting Results

View a phase, map to Output, and query vertical displacement at the curve point.

# Link a Stages phase to Output
g_i.view(phase2_s)
phase2_o = get_equivalent(phase2_s, g_o)

# Last curve point (added earlier)
curvepoint_o = g_o.CurvePoints.Nodes[-1]

# Vertical displacement at the point
uy_o = g_o.getcurveresults(curvepoint_o, phase2_o, g_o.ResultTypes.Soil.Uy)
print(uy_o)

# Explore other result types (interactive inspection)
# dir(g_o.ResultTypes.Soil)

Use Output’s plot tools for contours and vectors; the API enables scripted extraction for reports.

1️⃣2️⃣ Summary

  • Connected to PLAXIS servers and saved a new project.
  • Configured project type and domain; set borehole, layer, and groundwater head.
  • Defined hardening soil materials (drained vs. undrained) and assigned subgrade/embankment.
  • Generated a fine mesh and added an Output monitoring point.
  • Created staged phases, ran calculations, and performed Phi–c reduction safety analysis.
  • Queried Output results (e.g., settlement at a curve point).
Next-step ideas
  • Automate parametric material sweeps for sensitivity and FoS envelopes.
  • Batch-export safety factors and displacements into CSV for dashboards.
  • Script report figures (deformation, plastic points, excess pore pressures).