Modifying an XML file using Python
Save existing model as struxml
In most situations where a script or some kind of automation is needed it is easiest to modify an existing XML file. This can be done in many different ways and in many different programming languages. Start out by modelling the structure in FEM-Design as usual. Then save the model file as a XML-file. The model file can be saved as struxml file by going to "File/Save as..." and choosing struxml as the file type.
You can open and view the xml-file in a text editor to quickly identify what attribute or text that you want to modify. We recommend XML Notepad or Notepad ++.
Example 1 - Pile stiffness
Example 1 - Pile stiffness |
---|
The current example will illustrate how to modify an existing XML file to adjust the stiffness of a point support with regard to the reaction in the support. This will illustrate how to make changes to the model, run the analysis and then make additional changes depending on the result. This is a very common situation and the main work flow can be used in many different situations, for example optimization.
To better understand the final code, please see the picture below.
Import | ![]() |
Input | ![]() |
Identify and save original gamma factors | ![]() |
Read model file | ![]() |
Write new gamma factors with regard to load step | ![]() |
Run analysis | ![]() |
Read model file | ![]() |
Read reactions | ![]() |
Write new support stiffness | ![]() |
Example 2 - Parametric wall
Example 2 - Parametric wall |
---|
This example will illustrate how to create a parametric wall. The goal is to be able to adjust different measurements of an existing wall to make modelling more efficient and minimize errors. The example is a prefabricated wall and the measurements that should be parametric are:
Parameters | |
wallHeight | The total height of the wall [m] |
wallLength | The total length of the wall [m] |
windowX | The x-position of the window [m] |
windowY | The y-position of the window [m] |
windowW | The window width [m] |
doorPos | The position of the door [m] |
connectionCapacity | The connection capacity for each of the point connections [kN] |
The code will use an existing wall model saved as struxml and change different parameters with regard to the defined parameters. This file is included in the example. It is recommended to have some kind of input check so that the input values are possible to model, for example doorPos+1 < wallLength. This is however not included in the example.
Example 3 - Convergence study
Example 3 - Convergence study |
---|
This example will illustrate how to create a simple script to adjust the mesh settings to perform a convergence study. Please note that the script is using the FEM-Design Python wrapper. Download the wrapper and place it in the same folder as the script.
The script is also using the libraries Element tree, CSV and openpyexcel. They are available through pip install.
Disclaimer: All example files, wrappers and documentation are for illustrative and educational purposes and may not interact with FEM-Design in a reliable way depending on your version, installation and content of the files. Furthermore, StruSoft won´t guarantee full support of the API functions since they are customizable by the customer.