How to identify the material name of an object in Output using Python scripting


ApplicationPLAXIS 2D
PLAXIS 3D
VersionPLAXIS 2D 2023.2
PLAXIS 3D 2023.2
Date created21 September 2023
Date modified21 September 2023
Original authorStefanos Papavasileiou - Bentley Technical Support Group

Description

The PLAXIS Output program, apart from displaying calculation results of numerical analyses, also provides essential information on the model definition, such as assigned materials on soil/rock polygons or volumes as well as on structural elements, such as plates and embedded beams.

It is common to have different materials assigned to different objects depending on the settings applied in each phase. This is specified in the Staged construction in the PLAXIS Input program.

Figure 1. Example project and material shown for selected plate in Phase_7 (PLAXIS Input).

Figure 2. Material sets shown in PLAXIS Output

This article will show how to use the HTTP REST API / Remote Scripting feature to identify the material name used for plates in a particular phase.

Note that in this code example, we will use a case based on the PLAXIS 2D Tutorial 06: Dry excavation using a tie back wall project to describe how to retrieve the information required.

Python solution

Workflow overview

The PLAXIS Output material object contains a specific property to store the information on the material index shown in plots and tables. This depends on the material object itself, e.g., Soil, Plate, EmbeddedBeam, etc., and can be queried as:

g_o.ResultTypes.Plate.MaterialIndex

This property can be retrieved via the getresults command, which will return a list of material indices per element. Note that the “element” is a parameter of the getresults command; we can also query this per “node” and “stress point”. For example:

materialIndices = g_o.getresults(phase, g_o.ResultTypes.Plate.MaterialIndex, 'element')

The created list of material indices can now be queried to provide the .Identification property per element. The result can be another list, which will have the same order as the material index list (materialIndices) generated before.

materialNames = [g_o.Materials[index].Identification.value for index in materialIndices]

Since we want to show the material object for each plate, a separate list can be created for the plate .Name property:

plateNames = [plate_part.Name.value for plates in g_o.Plates for plate_part in plates]

Finally, the two created lists can be combined using Python’s zip() function, which can help print the contents side-by-side:

for plate_names in zip(plateNames, materialNames):
    print('\t'.join(["{}".format(i) for i in plate_names]))

Example with code

In the following example, we will use the information learnt to collect the material information and retrieve it using a simple Python script.

Let’s assume that in this project, a different plate material is assigned in the last phase of the project (Phase_7). Note that, generally, a Reduction of stiffness does not lead to a change in displacements.

This Python script aims to retrieve the material identification for every plate in the last two phases (Phase_6 and Phase_7) of the calculated project.

for phase in g_o.Phases[6:]: 
  plateNames = [plate_part.Name.value for plates in g_o.Plates for plate_part in plates] 
  materialIndices = g_o.getresults(phase, g_o.ResultTypes.Plate.MaterialIndex, 'element') 
  materialNames = [g_o.Materials[index].Identification.value for index in materialIndices] 
  print(phase.Name, "===========") 
 
  for plate_names in zip(plateNames, materialNames): 
    print('\t'.join(["{}".format(i) for i in plate_names]))

Figure 3. Python script providing the material identification per plate object for the last two phases (PLAXIS Output)

See also