api programming in femap - femap y nx nastran · 5/22/2012 page 1 api programming in femap 2015 sda...
TRANSCRIPT
5/22/2012Page 1
API Programming in Femap
2015 SDA FemapSymposium
Eric Gustafson/ [email protected]
SDA Femap SymposiumApril 14, 2015Steven F. Udvar-Hazy Center, National Air and Space MuseumChantilly, VA
5/22/2012Page 2
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/2012Page 3Page 3
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/2012Page 4
Hello World
API reference manual
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 feAppMessagemethod text to bring up the help info
5/22/2012Page 5Page 5
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/2012Page 6Page 6
Linking to Femap
Sub Main
Dim App As femap.model
Set App = feFemap()
End Sub
Sub Main
Dim App As femap.model
Set App = CreateObject(“femap.model”)
app.feAppVisible(True)
End Sub
Sub Main
Dim App As femap.model
Set App = GetObject(,“femap.model”)
End Sub
COM/OLE
Femap
Create a new Femap session
Connect to active model
Connect to active model in first opened instance of Femap
Interface Connection Syntax Comments
5/22/2012Page 7
API Programming Interfaces
API Programming Window
Calling scripts
5/22/2012Page 8
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/2012Page 9
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/2012Page 10
Declare and initialize node object
Declare and initialize set to store list of selected nodes
Declare and initialize set to store IDs of nodes referencing global csys
Declare and initialize group to store node IDs
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 )
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
Example – Group nodes using global coordinate system
5/22/2012Page 11
Use the select method of the set object to open a dialog for the user to select nodes to check
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 )
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
Using set.next() method in a while loop steps through all IDs
Adds current node to set if conditional statement checking the node reference is true
Example – Group nodes using global coordinate system
5/22/2012Page 12
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 )
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
Add all set IDs with nodes references global csys to new group (still in memory)
Put group to the model
Send text to the message window if no nodes meeting the condition were found
Example – Group nodes using global coordinate system
Single line
Single line
5/22/2012Page 13
Nodes 1-28 are defined with coordinate system 0, the rest are in coordinate system 3 (output and definition coordinate systems)
Example – Group nodes using global coordinate system
5/22/2012Page 14
Example – Group nodes using global coordinate system
5/22/2012Page 15Page 15
Data Types
Datatype Description Name Usage
INT4 4-byte integer
Long IDs
BOOL Single byte Boolean True/ False
REAL8 8-byte real Double Decimal numbers
VAR Variant Arrays
STRING Character string
String Text
• Use the right data type for your variable
Examples• Dim ID as long• Dim dMass as double
Cost commonly used datatypes
5/22/2012Page 16
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/2012Page 17
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
• Specify output set and vector
• Other recovery info
• Request envelope
• Set data needed
Populate
• Loads object with results data
Access
• Get individual values
• Get arrays of data
• Get min/max
5/22/2012Page 18
Custom User Dialogs Example
With the cursor in the dialog code, click on the “User Dialog” button
5/22/2012Page 19
What does SDA use the Femap API for?
Grouping- Check an entity’s group membership- Add group ID information to the Data
Table- Renumbering all entities in a group- Group entities that fail some modeling
practice check
Visibility/ Graphics- Show/ hide entities (solids, properties)- Render arrows for CBUSH released DOF
Mesh Editing- Split selected elements into new
property- Print out a list of independent or
dependent nodes on all selected RBEs
Mesh Editing (cont.)- Auto create and assign properties to
elements in each group- Update design changes as determined
from
Model checks- Check consistent PSHELL “extra” MIDs- Custom element quality checks
Laminates- Update one or more laminate property
value (failure theory, bondshr allowable, NSM, reference temp) at once for all selected laminate properties
Examples of scripts we’ve written in the past
5/22/2012Page 20
What does SDA use the Femap API for?
selected RBEs
- Update design changes as determined from
14,000+ orthogrid web and skin properties to update
“I ain’t updating this by hand”
5/22/2012Page 21
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• http://www.femapsymposium.com/presentations-from-femap-2014.html
5/22/2012Page 22
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 don’t 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 [email protected]
5/22/2012Page 23
API Programming in Femap
2015 SDA FemapSymposium
Eric GustafsonSenior Aerospace Stress Analyst/Femap Technical SupportStructural Design and Analysis, Incwww.structures.aero
46030 Manekin Plaza. Ste 120Sterling, VA 20166
Phone: (703) 657-0919Email: [email protected]
SDA Femap SymposiumApril 14, 2015Steven F. Udvar-Hazy Center, National Air and Space MuseumChantilly, VA