Eric Gustafson/ eric@structures.
aero
API Programming in Femap
SDA Femap Symposium
April 14, 2015 2015 SDA Femap
Steven F. Udvar-Hazy Center,
5/22/2012 National Air and Space Museum Symposium
Chantilly, VA Page 1
Agenda
How can the Femap API be used?
Hello World
Objects available to the API
Linking to Femap
API Programming Interfaces
The type library
Example API script
Data types
Arrays
Results browsing object
Custom user dialogs
What does SDA use the Femap API for?
Good references
Parting tips
5/22/2012
Page 2
How can the Femap API be used?
Automate or simplify redundant process steps
Create or edit model entities (node, elements, properties, etc)
Combine Femap commands to create new ones
Extract or create model results
Custom standalone programs and add-ins
Excel
exchanging info to and from worksheets
Word
for reporting
grab data and pictures
5/22/2012
Page 3
Hello World
Sub Main
Dim App As [Link]
Set App = feFemap()
[Link](FCM_NORMAL,"
Hello World")
End Sub
Press F1 with the
cursor in the
feAppMessage
method text to bring
up the help info API reference manual
5/22/2012
Page 4
Objects available through the API
API programming elements fall under one of three categories
1. Application object
Global properties and constants
Methods and utilities
Checking coincident nodes
Locking Femap window
2. Entity objects
Model entities such as nodes, points, properties, output, etc
3. Tool objects
Assist the creation and editing of entity objects
Data Table
Sets
Results Browsing object
Etc
Objects need to be declared and initialized (will cover later)
5/22/2012
Page 5
Linking to Femap
Interface Connection Syntax Comments
Femap Sub Main
Connect to active model
Dim App As [Link]
Set App = feFemap()
End Sub
Sub Main
COM/OLE Create a new Femap session
Dim App As [Link]
Set App = CreateObject([Link])
[Link](True)
End Sub
Sub Main
Connect to active model in
Dim App As [Link] first opened instance of
Set App = GetObject(,[Link])
Femap
End Sub
5/22/2012
Page 6
API Programming Interfaces
API
Programming
Window
Calling scripts
5/22/2012
Page 7
The Type Library
Advantages
Can view Femap API
objects outside of Femap
(object browser)
Popup tool tips will be
visible while programming
Note:
Must retain .tlb file or
update .tlb reference when
updating Femap versions
If not using the type
library, cannot use the Dim
App As [Link]
syntax. Must use Dim App
As object instead.
5/22/2012
Page 8
Example Group nodes using global
coordinate system
Goal
Group all nodes that reference the global coordinate system
Why
Some programs have strict guidelines for organization of Nastran decks
Will demonstrate use of
Select dialog
Sets
Looping through set IDs
Reading object properties
Creating a new database object (a group)
Printing text to the message window
5/22/2012
Page 9
Example Group nodes using global
coordinate system
Declare and initialize node object
Dim nd As [Link]
Set nd = [Link] Declare and initialize set to
Dim nodesSelected As [Link] store list of selected nodes
Set nodesSelected= [Link]
Dim nodesInGlobal As [Link] Declare and initialize set to store IDs of
Set nodesInGlobal = [Link] nodes referencing global csys
Dim gr As [Link] Declare and initialize group
Set gr = [Link]
to store node IDs
rc=[Link](FT_NODE, True, "Select Nodes to Check Csys" )
If rc <> FE_OK Then Exit Sub
While [Link]()
[Link]( [Link] )
If ([Link] = 0) Or ([Link] = 0) Then [Link]( [Link] )
Wend
If [Link] > 0 Then
[Link] ( FT_NODE, [Link] )
[Link] = Str$([Link]) + " node(s) referencing global csys"
[Link]([Link]) [Link] (FCM_ERROR,
Str$([Link]) + " nodes found to reference the global csys")
Else
[Link] (FCM_NORMAL, "No selected nodes reference the
global csys")
End If
5/22/2012
Page 10
Example Group nodes using global
coordinate system
Dim nd As [Link]
Set nd = [Link]
Dim nodesSelected As [Link]
Use the select method of the set
Set nodesSelected= [Link] object to open a dialog for the user
Dim nodesInGlobal As [Link] to select nodes to check
Set nodesInGlobal = [Link]
Dim gr As [Link]
Set gr = [Link]
rc=[Link](FT_NODE, True, "Select Nodes to Check Csys" )
If rc <> FE_OK Then Exit Sub
Using [Link]() method in a
While [Link]() while loop steps through all IDs
[Link]( [Link] )
If ([Link] = 0) Or ([Link] = 0) Then [Link]( [Link] )
Wend
Adds current node to set if
If [Link] > 0 Then conditional statement checking the
[Link] ( FT_NODE, [Link] ) node reference is true
[Link] = Str$([Link]) + " node(s) referencing global csys"
[Link]([Link]) [Link] (FCM_ERROR,
Str$([Link]) + " nodes found to reference the global csys")
Else
[Link] (FCM_NORMAL, "No selected nodes reference the
global csys")
End If
5/22/2012
Page 11
Example Group nodes using global
coordinate system
Dim nd As [Link]
Set nd = [Link]
Dim nodesSelected As [Link]
Set nodesSelected= [Link]
Dim nodesInGlobal As [Link]
Set nodesInGlobal = [Link]
Dim gr As [Link]
Set gr = [Link]
rc=[Link](FT_NODE, True, "Select Nodes to Check Csys" )
If rc <> FE_OK Then Exit Sub
While [Link]()
[Link]( [Link] )
If ([Link] = 0) Or ([Link] = 0) Then [Link]( [Link] ) Add all set IDs with nodes
Wend references global csys to new
If [Link] > 0 Then group (still in memory)
[Link] ( FT_NODE, [Link] )
[Link] = Str$([Link]) + " node(s) referencing global csys" Put group to the model
[Link]([Link]) [Link] (FCM_ERROR,
Single line
Str$([Link]) + " nodes found to reference the global csys")
Else
[Link] (FCM_NORMAL, "No selected nodes reference the Send text to the message
Single line
global csys") window if no nodes
End If meeting the condition
5/22/2012
were found Page 12
Example Group nodes using global
coordinate system
Nodes 1-28 are defined
with coordinate system
0, the rest are in
coordinate system 3
(output and definition
coordinate systems)
5/22/2012
Page 13
Example Group nodes using global
coordinate system
5/22/2012
Page 14
Data Types
Cost commonly used datatypes
Use the right data type Datatype Description Name Usage
for your variable INT4 4-byte Long IDs
integer
Examples BOOL Single byte Boolean True/ False
Dim ID as long
REAL8 8-byte real Double Decimal numbers
Dim dMass as double
VAR Variant Arrays
STRING Character String Text
string
5/22/2012
Page 15
Arrays
For output, arrays must
be passed as variant
data type
Example
Dim vbase As Variant
Dim vdist As Variant
Dim dDist As Double
[Link]
BetweenNodes(1,2,0,0,0
,vbase,vdist,dDist)
5/22/2012
Page 16
Results Browsing Object
Generally speaking, do not involve time-consuming loops to extract results
Use an RBO to place data in memory, perform operations on it, and then retrieve
data quickly
Setup Populate Access
Specify output set and Loads object with results Get individual values
vector data Get arrays of data
Other recovery info Get min/max
Request envelope
Set data needed
5/22/2012
Page 17
Custom User Dialogs Example
With the cursor in the dialog
code, click on the User Dialog
button
5/22/2012
Page 18
What does SDA use the Femap API for?
Examples of scripts weve written in the past
Grouping Mesh Editing (cont.)
- Check an entitys group membership - Auto create and assign properties to
- Add group ID information to the Data elements in each group
Table - Update design changes as determined
- Renumbering all entities in a group from
- Group entities that fail some modeling
practice check Model checks
- Check consistent PSHELL extra MIDs
Visibility/ Graphics - Custom element quality checks
- Show/ hide entities (solids, properties)
- Render arrows for CBUSH released DOF Laminates
- Update one or more laminate property
Mesh Editing value (failure theory, bondshr allowable,
- Split selected elements into new NSM, reference temp) at once for all
property selected laminate properties
- Print out a list of independent or
5/22/2012
dependent nodes on all selected RBEs Page 19
What does SDA use the Femap API for?
- Update design changes as determined
from
selected RBEs
14,000+ orthogrid web and skin
properties to update
I aint updating this by hand
5/22/2012
Page 20
Good References
API Reference Manual
[Link] in the \pdf folder in the Femap install directory
Learning from existing installed APIs under Custom Tools
Found under the \API folder in the Femap install directory
Source code can be viewed in Femap or a text editor
\pdf\[Link]
APIs occasionally posted to the Siemens Femap Blog
[Link]
Femap Symposium Presentations by Patrick Kriengsiri
Introduction to the Femap API (2014)
Advanced API programming (2014)
Advanced Post-Processing with the Femap API (2013)
[Link]
5/22/2012 [Link]
Page 21
Parting Tips
Start small
Use pseudocode
Examples can assist the learning process, can use the source code of
preinstalled API files
Learn the scripting in Femap first, then venture into interacting with Femap
from other programs
Where possible, use helper methods that push and pull larger amounts
of data to and from a model at a time to reduce overhead
If you dont see a change immediately reflected in Femap, you may need to
rebuild or redraw
[Link]/ [Link]
[Link]
Feel free to reach out to the SDA support team during the symposium or
after at support@[Link]
5/22/2012
Page 22
API Programming in Femap
Eric Gustafson
Senior Aerospace Stress Analyst/
Femap Technical Support
Structural Design and Analysis, Inc
[Link]
46030 Manekin Plaza. Ste 120
Sterling, VA 20166
Phone: (703) 657-0919
Email: eric@[Link]
SDA Femap Symposium
April 14, 2015
Steven F. Udvar-Hazy Center,
2015 SDA Femap
5/22/2012 National Air and Space Museum Symposium
Chantilly, VA Page 23