Getting started
Python is a versatile, high-level, and dynamically-typed programming language known for its simplicity and readability. Python enables developers to build a wide range of applications, from web development to data science, automation, and beyond.
This guide shows how to create and run a Python script using Visual Studio Code and the Python command-line interface (CLI). Project tasks, such as creating, editing, and running a script, are managed through the terminal.
The python package is mainly focus on fdscript automation which will help you in automatise processes as running analysis, design and read results.
The python package now provides interop.py where the XSD schema is converted to Python dataclasses for working with the Database object. Two methods are available to:
- Serialize Python dataclasses to struxml format
- Deserialize struxml files to
Databaseobjects
Prerequisities
-
Visual Studio Code with the Python extension installed. For information about how to install extensions on Visual Studio Code, see VS Code Extension Marketplace.
-
FEM-Design Python API which can be install by
pip install FEM-Designthrough your terminal.
Create a python script
-
Start Visual Studio Code.
-
Select File > Open Folder from the main menu.
-
In the Open Folder dialog, create a HelloStruSoft folder and select it. Then click Select Folder
-
Create a new file and save it as program.py.
-
Copy the following script contents in program.py with the following code:
from femdesign.comunication import *
from femdesign.calculate import *
from femdesign.interop import *
from femdesign.io import *
INPUT_STRUXML = r"simple_beam.struxml" # replace with your struxml file path
OUTPUT_STRUXML = r"simple_beam_out.struxml"
SAVED_STR = r"simple_beam_with_results.str"
model = deserialize_from_filepath(INPUT_STRUXML) # replace with your struxml file path
model.country = Eurocodetype.S
model.entities.supports.point_support[0].group.rigidity.motions.x_neg = 0
model.entities.supports.point_support[0].group.rigidity.motions.x_pos = 0
serialize_to_struxml(model, OUTPUT_STRUXML)
pipe = FemDesignConnection(minimized= False)
try:
pipe.Open(OUTPUT_STRUXML)
static_analysis = Analysis.StaticAnalysis()
pipe.RunAnalysis(static_analysis)
pipe.Save(SAVED_STR)
except Exception as err:
pipe.KillProgramIfExists()
raise err
Run the application
Run the following command in the Terminal:
python program.py
Congratulations, you have successfully created your first FEM-Design Application! 🎉
A small range of examples can be found at GitHub.
If you need any help or you are looking for new features, give us some feedback by our Community page.