Modifying an XML file using Python

Last modified by Iwona Budny Bjergø on 2019/09/11 11:35

More in this chapter:


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.

1556898277772-731.png

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⭳ Download example 1

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. 

Import1560771158116-573.png
Input1560771182141-325.png
Identify and save original gamma factors1560771228867-938.png
Read model file1560771289380-245.png
Write new gamma factors with regard to load step1560771347907-586.png
Run analysis1560771478731-491.png
Read model file1560771542309-517.png
Read reactions1560771684392-495.png
Write new support stiffness1560771755994-352.png

NOTE: To get the script to work you have to check the file path inside the python code and also in the script-file.

1557159371286-480.png1557159404913-728.png

Example 2 - Parametric wall

Example 2 - Parametric wall⭳ Download example 2

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 
wallHeightThe total height of the wall [m]
wallLengthThe total length of the wall [m]
windowXThe x-position of the window [m]
windowYThe y-position of the window [m]
windowWThe window width [m]
doorPosThe position of the door [m]
connectionCapacityThe connection capacity for each of the point connections [kN]

1557146467475-391.png

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.

NOTE: Place the python script and the model file in the same directory to get the code to run.


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.

Tags: API
Created by IwonaBudny on 2019/02/07 13:12
   
Copyright 2019 StruSoft AB
FEM-Design Wiki