top of page
Writer's pictureHichem Djadoudi

How to Define and Automate Properties in FEMAP Using the API: Step by Step Guide 2024

Updated: Mar 21

Finite Element Analysis (FEA) is an invaluable resource for engineers and researchers aiming to understand complex systems. While material properties lay the foundation for an accurate FEA model, properties that combine materials with geometric data are equally pivotal. Manually defining these properties can be a tedious and error-prone task. But what if we could automate this process, ensuring precision and consistency every time? With FEMAP's API and VBScript, this becomes a reality. In this guide, we will embark on a journey to harness the power of automation, not just to simplify our modeling process, but to transform it. By integrating automation, you can manage multiple projects effortlessly, mitigate human errors, save valuable time, and establish a uniform modeling approach across various projects. So, are you ready to elevate your FEA modeling prowess? Let's dive deep and unravel the magic of property automation!

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. Defining the Materials that will be used by the properties with API


Materials are the backbone of your analysis. To dive into details about Material creation refer to our previous tutorial on how to Automation Material definition here


Script Material Definition FeMAP using API

(You can similarly define other materials using the above format.)


3. Building the Composite Layer


If you're dealing with composites, defining laminate properties becomes essential.To dive into details about Layup creation refer to our previous tutorial on how to Automation layup definition here




Script Layup definition Through Femap API


4. Defining Properties


In FEMAP, properties combine material characteristics with geometry data to define how elements will behave in response to loads. The property will refer to a specific material (or layup for composite materials) and will also contain geometric information pertinent to the element type, such as thickness for plates or area for rods.


Script on how to create Properties through FEMAP API

  • Prop.title: This sets the name of the property.

  • Prop.type: This defines the type of property, in this case, a rod.

  • Prop.matlID: This specifies which material this property is associated with. We're using material 1 which we defined earlier.

  • Prop.flag(): This is an array used to define specific behaviours or parameters for properties.

  • Prop.pval(): This array contains values specific to the property type. For a rod, it typically includes the cross-sectional area, among other parameters.

  • Prop.Put(1): This writes the property to the database with the ID 1

5. Testing Your Script


After writing and understanding your script, it’s vital to test its functionality. Here's how:

  1. Execute the Script: Run your script in the FEMAP API window by pressing the 'Run' button. If there are any errors, FEMAP will notify you. If this occurs, review the code, fix any issues, and try running the script again.

  2. Review the FEMAP Model: After successfully running the script, check the FEMAP model tree to ensure that the materials, properties, and other elements have been added as intended. Review the properties and attributes of each item to ensure accuracy.



testing the Script for Properties creation


  1. Debugging: If there's any unexpected behavior, use MsgBox or other debugging techniques to troubleshoot problematic areas of your code

6. 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.


7. 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 6

  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.



Adding the script API to the UI of Femap


Congratulations!😎 You've successfully created a script to automate the creation of properties in FEMAP, learned how to save, organize, and quickly run it from within the software. This kind of automation can be a massive time-saver, especially for repetitive tasks. Remember, the possibilities are endless with scripting – you can adapt and extend your scripts to suit any project's requirements by creating several folders for projects and saving within each folder the properties belonging to the project, streamlining your FEMAP workflows even further. Happy coding!


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 "How to Define and Automate Properties in FEMAP Using the API" to ensure automatic delivery.


Coming Up Next

Eager to enhance your FEMAP scripting skills further? Stay tuned for our next guide on "FEMAP API: Looping Through Various Object Entities (Geometry, Materials, Properties, Loads and more)" More insights, more automation!

Comments


bottom of page