Application | PLAXIS 2D |
Version | PLAXIS 2D |
Date created | 26 June 2019 |
Date modified | 26 June 2019 |
In PLAXIS 2D, you may want to know all the coordinates of a polygon in order to use it in your Python/scripting environment. When looking at the items in the Selection Explorer in the PLAXIS 2D User Interface when selecting such a polygon, we nicely see all the corner points with their coordinates. However, the internal structure of the polygon object stores these polygon-points as a combination of a base insertion point and a list of so-called HelperPoints (e.g. Polygon_1.Points). These HelperPoints are relative to this insertion point.
Figure 1. Selected polygon (right) with the polygon points on the right in the selection explorer
Attached here is a small snippet for extracting this as a list of (x, y)-tuples and returning this list to be used in your Python script.
def getpolygoncoords(pg): """ reads all coordinates of the specified polygon and returns a list """ # get insertion point base_x = pg.x.value base_y = pg.y.value # loop over all HelperPoints and return coordinates return [(base_x + i.x.value, base_y + i.y.value) for i in pg.Points] # EXAMPLE: now loop over all polygons to print all the coordinates g_i.gotostructures() for polygon in g_i.Polygons[:]: print("{}: {}".format(polygon.Name.value, getpolygoncoords(polygon)))
Note: this only works for Polygons in Structures mode, not for soil polygons created by a borehole.