top of page

FEMAP API 2024: Looping Through Various Object Entities (Geometry, Materials, Properties, Loads and more)

Updated: Feb 3

FEMAP is a powerful engineering simulation software. One of its lesser-known features is its ability to be automated using scripting. In this tutorial, we will dive deep into a script that loops through various model entities like points, curves, elements, materials, properties, layups, and load sets. By the end of this tutorial, you'll have a clear understanding of how to use the FEMAP API to extract and manipulate data within your FEMAP models.

With these scripts, you can quickly extract valuable information from your FEMAP models, be it for validation, report generation, or any other purpose. By understanding the structure and methodology of this script, you can further customize it to cater to your specific needs or to extract other types of information from your models. Happy scripting!

To have the script file ( .BAS) used in this guide click here

Difficulty Level: Beginner


 

Table of Contents:


 

Prerequisites

  • Basic knowledge of FEMAP.

  • Familiarity with VBScript.



 

1. Setting Up the FEMAP API Coding Environment


1.1 Accessing the API Programming Window


Launch FEMAP.

From the main menu, select Tools >Programming > API Programming.

This will open the API programming window where you can input your VBScript.


1.2 Recognizing the Initial API Code Lines


When you open the API Programming window, you'll notice two lines of code already present:

Initialization femap API SCREENSHOT

  1. Dim App As femap.model: This line declares a variable named "App" as an instance of the FEMAP model. In simpler terms, it's setting up a reference that our script will use to communicate and interact with the FEMAP model environment.

  2. Set App = feFemap(): With this line, our previously declared "App" variable is initialized or linked directly to the active FEMAP session. The feFemap() function is FEMAP's way of saying, "Hey, I want to connect to the current FEMAP model."

This connection is crucial, as it allows the subsequent script commands to create or modify data within the FEMAP environment.


2. Looping Mechanism Explanation


Many entities in FEMAP, such as points, curves, materials, and others, are organized in collections. The script uses the .Next method to traverse these collections.

The .Next method returns True if there's another entity in the collection and automatically moves the internal pointer to that entity. This allows for easy looping through all entities in a collection.


3. Interacting with Points Using Femap API


Points are fundamental entities in any finite element model. The script accesses and displays information about each point in the model:

Script to loop over Points object with Femap API

  • Dim Point As femap.Point: Declares a variable Point of type femap.Point.

  • Set Point = App.fePoint: Initializes the Point variable to the collection of points in the current model.

  • While Point.Next: Begins a loop that continues as long as there are more points in the collection.

  • Msg = "Point ID" + Str$(Point.ID): Constructs a message string containing the ID of the current point.

  • re = App.feAppMessage (FCM_NORMAL, Msg): Displays the constructed message in FEMAP's message window.



4. Interacting with Other Entities Using Femap API


The script uses a similar structure to loop through other entities, such as curves, elements, materials, properties, layups, and load sets. For each entity:

  1. A variable of the appropriate type is declared.

  2. The variable is initialized to the corresponding collection in the model.

  3. A While loop using the .Next method iterates through the collection.

  4. Information about the current entity is constructed into a message string.

  5. The message is displayed in FEMAP's message window.

Below is some exemple of script for different object:



5. Looping Through Curves Using Femap API


Similarly, we can loop through the curves:


Script to loop over Curves object with Femap API


6. Looping Through Elements Using Femap API


The element loop is slightly more advanced because we're applying a condition:


Script to loop over Element object with Femap API

In this loop, we're only interested in elements of type QUAD4. If the element is of this type, its ID is displayed.



7. Looping Through Materials Using Femap API


The next sections loop through materials:


Script to loop over Material object with Femap API

Within each of these loops, the script will display the ID and name/title of each material



8. Looping Through Property Using Femap API


The next sections loop through Properties:


Script to loop over Properties object with Femap API

Within each of these loops, the script will display the ID and name/title of each Property



9. Looping Through LayUps Using Femap API


The next sections loop through Layups:


Script to loop over Layups object with Femap API

Within each of these loops, the script will display the ID and name/title of each Layup



10. Looping Through LoadSets Using Femap API


Lastly, we loop through the load sets:


Script to loop over  Load sets object with Femap API

Within each of these loops, the script will display the ID and name/title of each load set



11. Saving the Script to a Specific Folder


Once you're confident in your script's performance:

  1. Navigate to 'Save As' in the API programming window.

  2. Choose a dedicated folder for your FEMAP scripts to keep them organized.

  3. Save the script with a descriptive name, using the .bas file extension.


12. Adding the Script to FEMAP's Custom Tools Menu


To quickly access and run your script directly from FEMAP:

  1. In FEMAP, go to 'User Tools' > 'Tools Directory'

  2. Select the folder containing the '.BAS' file saved in step 11

  3. Then click on 'User Tools' you will see all your '.bas' file listed

  4. By clicking on one of them it will execute the script directly

Now, whenever you want to run this script in FEMAP, you can quickly access it directly from the 'User Tools' > 'Your ScriptName', as shown in the video Below.



Screenshot script testing of looping through objects with Famap API


Get the .bas File

Interested in getting the .bas file used in this guide? Email us at support@worquick.com, and we'll send it to you in a flash. Make sure to have the subject line as "FEMAP API: Looping Through Various Object Entities" to ensure automatic delivery.


Coming Up Next

Eager to enhance your FEMAP scripting skills further? Stay tuned for our next guide on "Defining and Automating Loads in FEMAP Using the API Environment." More insights, more automation!

Comments


bottom of page