5249x
001769
2022-10-26

Aplicações práticas com o Python e o RFEM 6 | Gerador de treliças 2D

Os recentemente introduzidos serviços web oferecem aos utilizadores a possibilidade de comunicar com o RFEM 6 utilizando a linguagem de programação da sua escolha. Esse recurso é aprimorado com nossa biblioteca de funções de alto nível (HLF). As bibliotecas estão disponíveis para Python, JavaScript e C#. Este artigo analisa um caso de aplicação prática da programação de um gerador de treliças 2D com Python. "Aprender na prática", como diz o ditado.

Prefácio

Utilizar o poder do RFEM 6 para além da interface gráfica do utilizador (GUI) e controlar/automatizar o modelo e o processo de dimensionamento são uma vantagem considerável. 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:

Vídeos de e-learning | Programação com RFEM 6 e 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:

Guia de referência do 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.

Programação com RFEM 6 e Python | 006 Exemplo | Estrutura de treliça plana

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.

Considerações finais

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.


Ligações


;