You are on page 1of 23

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 femap.model


Set App = feFemap()

App.feAppMessage(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 femap.model
Set App = feFemap()

End Sub

Sub Main
COM/OLE Create a new Femap session
Dim App As femap.model
Set App = CreateObject(femap.model)
app.feAppVisible(True)

End Sub

Sub Main
Connect to active model in
Dim App As femap.model first opened instance of
Set App = GetObject(,femap.model)
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 femap.model
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 femap.Node
Set nd = App.feNode Declare and initialize set to
Dim nodesSelected As femap.Set store list of selected nodes
Set nodesSelected= App.feSet
Dim nodesInGlobal As femap.Set Declare and initialize set to store IDs of
Set nodesInGlobal = App.feSet nodes referencing global csys
Dim gr As femap.Group Declare and initialize group
Set gr = App.feGroup
to store node IDs
rc=nodesSelected.Select(FT_NODE, True, "Select Nodes to Check Csys" )
If rc <> FE_OK Then Exit Sub

While nodesSelected.Next()
nd.Get( nodesSelected.CurrentID )
If (nd.defCSys = 0) Or (nd.outCSys = 0) Then nodesInGlobal.Add( nd.ID )
Wend

If nodesInGlobal.Count > 0 Then


gr.SetAdd ( FT_NODE, nodesInGlobal.ID )
gr.title = Str$(nodesInGlobal.Count) + " node(s) referencing global csys"
gr.Put(gr.NextEmptyID) App.feAppMessage (FCM_ERROR,
Str$(nodesInGlobal.Count) + " nodes found to reference the global csys")
Else
App.feAppMessage (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 femap.Node
Set nd = App.feNode
Dim nodesSelected As femap.Set
Use the select method of the set
Set nodesSelected= App.feSet object to open a dialog for the user
Dim nodesInGlobal As femap.Set to select nodes to check
Set nodesInGlobal = App.feSet
Dim gr As femap.Group
Set gr = App.feGroup

rc=nodesSelected.Select(FT_NODE, True, "Select Nodes to Check Csys" )


If rc <> FE_OK Then Exit Sub
Using set.next() method in a
While nodesSelected.Next() while loop steps through all IDs
nd.Get( nodesSelected.CurrentID )
If (nd.defCSys = 0) Or (nd.outCSys = 0) Then nodesInGlobal.Add( nd.ID )
Wend
Adds current node to set if
If nodesInGlobal.Count > 0 Then conditional statement checking the
gr.SetAdd ( FT_NODE, nodesInGlobal.ID ) node reference is true
gr.title = Str$(nodesInGlobal.Count) + " node(s) referencing global csys"
gr.Put(gr.NextEmptyID) App.feAppMessage (FCM_ERROR,
Str$(nodesInGlobal.Count) + " nodes found to reference the global csys")
Else
App.feAppMessage (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 femap.Node
Set nd = App.feNode
Dim nodesSelected As femap.Set
Set nodesSelected= App.feSet
Dim nodesInGlobal As femap.Set
Set nodesInGlobal = App.feSet
Dim gr As femap.Group
Set gr = App.feGroup

rc=nodesSelected.Select(FT_NODE, True, "Select Nodes to Check Csys" )


If rc <> FE_OK Then Exit Sub

While nodesSelected.Next()
nd.Get( nodesSelected.CurrentID )
If (nd.defCSys = 0) Or (nd.outCSys = 0) Then nodesInGlobal.Add( nd.ID ) Add all set IDs with nodes
Wend references global csys to new
If nodesInGlobal.Count > 0 Then group (still in memory)
gr.SetAdd ( FT_NODE, nodesInGlobal.ID )
gr.title = Str$(nodesInGlobal.Count) + " node(s) referencing global csys" Put group to the model
gr.Put(gr.NextEmptyID) App.feAppMessage (FCM_ERROR,
Single line
Str$(nodesInGlobal.Count) + " nodes found to reference the global csys")
Else
App.feAppMessage (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
App.feMeasureDistance
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


API.pdf 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\CustomTools.pdf

APIs occasionally posted to the Siemens Femap Blog


https://community.plm.automation.siemens.com/t5/Femap-Blog/bg-p/Femap-news

Femap Symposium Presentations by Patrick Kriengsiri


Introduction to the Femap API (2014)
Advanced API programming (2014)
Advanced Post-Processing with the Femap API (2013)
http://www.femapsymposium.com/presentations-from-femap-2013.html
5/22/2012 http://www.femapsymposium.com/presentations-from-femap-2014.html
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
App.feViewRegenerate/ app.feViewRedraw
App.feFileRebuild
Feel free to reach out to the SDA support team during the symposium or
after at support@structures.aero

5/22/2012
Page 22
API Programming in Femap
Eric Gustafson
Senior Aerospace Stress Analyst/
Femap Technical Support
Structural Design and Analysis, Inc
www.structures.aero

46030 Manekin Plaza. Ste 120


Sterling, VA 20166

Phone: (703) 657-0919


Email: eric@structures.aero

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

You might also like