How to create a tunnel using Python

23 May 2017


The following article gives information on how to use the Remote scripting feature to create a tunnel using the PLAXIS tunnel designer.

In this example, we will show the Python commands to generate the tunnel cross-section of Tutorial Lesson 7 (Excavation of a NATM tunnel) [link].

The geometry of NATM tunnel in the tutorial lesson

To better understand the structure of the commands used in the example, some are explained below:

  • set command
    • set is used in PLAXIS Input to set one or more properties of one or more objects. An example is the following:
      set Tunnel_1.CrossSection.Segments[0].ArcProperties.Radius 10.4

      With Python, the set command can be written using the assignment statement set command
      (name = expression):

      g_i.Tunnel_1.CrossSection.Segments[1].ArcProperties.Radius = 10.4
  • commands with no parameters
    • In PLAXIS Input some of the commands do not have any parameters defined (as optional). One case is the following command as it is generated in the Input program:
      add Tunnel_1.CrossSection

      With Python, the command can be written in the following way:


      Note that the empty field in the parentheses indicate that there are no parameters defined for this method (command).


Tutorial 6 - Excavation of a NATM tunnel (Python commands)

# define the tunnel and assign a variable to it
tunnel = g_i.tunnel(0, 16)

# first segment defined command by command
tunnel.CrossSection.Segments[-1].SegmentType = "Arc"
tunnel.CrossSection.Segments[-1].ArcProperties.Radius = 10.4
tunnel.CrossSection.Segments[-1].ArcProperties.CentralAngle = 22

# function for the rest of segments
def add_arc(tunnel, radius, angle):
    segment = tunnel.CrossSection.add()
    segment.SegmentType = "Arc"
    segment.ArcProperties.Radius = radius  
    segment.ArcProperties.CentralAngle = angle

# call the function to create two more segments
add_arc(g_i.Tunnels[-1], 2.4, 47)
add_arc(g_i.Tunnels[-1], 5.8, 50)

# extend to symmetry axis and symmetrically close the shape

# add subsections
subsection, subsection_segment = tunnel.CrossSection.addsubcurve()
subsection.Offset2 = 3
subsection_segment.SegmentType = "Arc"
subsection_segment.ArcProperties.Radius = 11
subsection_segment.ArcProperties.CentralAngle = 360

# create a list for all segments and subsections that will be intersected
segments_subsections = []
for subsection in tunnel.CrossSection.Subsections[:]:
    for segment in tunnel.CrossSection.Segments[:]:

# intersect the created list and delete the odd one

# define plates for slice polycurves, assign material, create negative interface
for tunnel_slice in tunnel.SliceSegments[:]:
    # next command requires a material to be predefined for the lining
    tunnel_slice.Plate.Material = g_i.Lining
    if tunnel_slice == tunnel.SliceSegments[4] or tunnel_slice == tunnel.SliceSegments[5]:

# generate the tunnel

The goal of this example is to show how to use Python to create a tunnel in PLAXIS 2D: its focus is on the geometry creation. To run this script, a plate material (named Lining) already needs to be defined in the current project.

Privacy Preference Center


The Cookies are necessary for the site to function

CONSENT, NID, _cfduid, wp-settings-time-16, wp-setting-16, wordpress_test_cookie, gdpr[allowed_cookies], gdpr[consent_types], wp_woocommerce_session, wordpress_logged_in, wordpress_sec, PHPSESSID


These Cookies are used to provide you with useful information based on recent browser data

UserMatchHistory, lang, BizoID
lidc, bcookie


These are used to track user interaction and detect potential problems. These help us improve our services by providing analytical data on how users use this site

_ga, _gid