A Simple Femap API Program Tutorial: This program takes a list of element ID in an Excel workbook and creates a group containing them in Femap. This is a continuation of tutorial 4.

1) Execute tutorial 4 to generate some elements in Femap or use any model that contains elements.

2) Follow steps 1 to 4 in tutorial 1 to add a command button to the worksheet

3) In Excel populate column 1 with some element IDs to put in the group, the first cell will be taken to be the group title.

4) The code :-

Option Explicit

Private Sub CommandButton1_Click()
Dim gfemap As Object
Dim oGp As Object
Dim oSet As Object
Dim iRow As Integer
Dim sTitle As String
Dim iGpId As Long
Dim WS As Worksheet
Dim lEID As Long
‘Get the open femap session
Set gfemap = GetObject(, “femap.model”)

‘Set oGp to a femap group object which is derived from an entity object
‘so all the entity object method and properties are applicable as well
‘ as the specific group object methods and properties
‘This is the object you need to create to get group in femap
Set oGp = gfemap.feGroup
‘Set oSet to an feset object this used to store and operate on lists of IDs
‘it is not derived from an entity object
Set oSet = gfemap.feset
Set WS = ThisWorkbook.Worksheets(“sheet1”)

iRow = 1
‘Get the group Title
sTitle = WS.Cells(iRow, 1)
iRow = 2
‘loop the cells in col 1 to get the element IDS
Do While WS.Cells(iRow, 1) <> “”
lEID = WS.Cells(iRow, 1)
‘Add the id retrieved to the femap set
oSet.Add (lEID)
iRow = iRow + 1
Loop
‘ Here we add the IDs to the group also indicating what type of object (type 8 – Element)
‘ they are.
oGp.setadd 8, oSet.ID
‘We now retrieve a unique group ID by call the entity objects NextEmptyID method.
‘Not this method is common to all objects derived from the entity object. This could have been
‘ an element object and the call to NextEmptyID would retrieve a unique unused element ID
iGpId = oGp.NextEmptyID
‘Set the groups title property
oGp.Title = sTitle
‘Put the goup into femap at the unique group ID
oGp.Put (iGpId)

End Sub

5) In Femap there should now be a new group containing  just the elements listed in the Excel workbook as illustrated below:-

The next tutorial introduces a vector class.