5507x
001769
2022-10-26

Python 和 RFEM 6 的实际应用 | 2D 桁架生成器

通过最近引入的网络服务 (Webservices),用户可以使用自己选择的编程语言与 RFEM 6 进行交互。 我们的高级函数 (HLF) 库对该功能进行了增强。 这些库适用于 Python、JavaScript 和 C#。 本文介绍了一个使用 Python 编写二维桁架生成器的实际用例。 俗话说“边做边学”。

概况

除了图形用户界面 (GUI) 之外,使用 RFEM 6 的强大功能以及控制/自动化建模和设计过程是一个相当大的优势。 However, the power of programming with RFEM 6 goes beyond mere automatic control. Users can combine the RFEM 6 HLF Library with other popular HLF Libraries to develop custom Applications.

In this article, a 2D Truss Generator will be presented. The 2D Truss Generator was written in Python and utilizes powerful Python Libraries such as PyQt and Numpy in combination with the RFEM HLF. The end result is a GUI, which allows for a flexible truss generation.

Learning Basics

This article will only highlight portions of code unique to its application in developing the 2D Truss Generator. The basics of Programming with RFEM 6 and Python can be found in our short 6-part video series under the following link:

B 站视频主页 | 使用 RFEM 6 和 Python 进行编程

Following Along

The code for this example can be found in the aforementioned HLF Library (RFEM_Python_Client/Examples/TrussGenerator_2D). The code is provided as open-source and hopefully provides users with inspiration for their own projects. Details on working with the RFEM HLF (for example, cloning the repository) are explained in the video series linked above.

Specific Portions of Code

Try and Except

As mentioned, this example uses many different libraries in conjunction with the RFEM HLF (for example, Numpy and PyQt5). Should users not have a specific library installed, an "import" command will throw an error. To overcome this potential issue, try and except blocks are used. The "import" falls under the try block and should this fail, the code goes into the except block, which will prompt the user to install the required libraries using pip.

Building the GUI using PyQt5

PQt5 is a library aimed at the creation of GUIs. A large proportion of the code is comprised of the definitions and statements required by PyQt5 for building the 2D Truss Generator GUI.

Documentation for using PyQt5 can be found under their link:

PyQt5 参考指南

A plethora of tutorials can also be found on YouTube.

Truss Definition

Using the RFEM HLFs, a truss can be defined rapidly. For support on programming a truss, follow the sixth video in the aforementioned video series.

使用 RFEM 6 和 Python 进行编程 | 006 示例 | 平面桁架

Variables initialized in the PyQt5 definitions are also integrated here as arguments for the RFEM truss definitions. This creates interoperability between the two libraries.

A series of try, except, and if statements are deployed to validate information provided in the GUI.

Final Remarks

The above article seeks to give a brief overview of how a parametric 2D Truss Generator GUI was created. Should extra information be required, please use the comments section on this article and we will be happy to respond.


链接


;