A Simple Femap API Program Tutorial: to automatically create a Femap loadset and apply some nodal forces.

Step 1 : Follow tutorial 4 to create the patch of element shown below:-

the node labels are shown and range from 1 to 121

2) Create a new workbook and add a command button on sheet 1 as demonstrated in tutorial 1. Fill columns 1 to 4 with dummy node id,Fx,Fy,Fz values to apply for nodes 1 to 121 as illustrated below:-

3) The Code :-

Option Explicit

 

Private Sub CommandButton1_Click()

Dim gfemap As Object

Dim LoadSet As Object

Dim Load As Object

Dim lLsetID  As Long

Dim i As Integer

Dim lNID As Long

Dim dFx As Double

Dim dFy As Double

Dim dFz As Double

Dim iRow As Integer

Dim WS As Worksheet

Set WS = ThisWorkbook.Worksheets(1)

iRow = 2                                                          ‘start row of our data in Excel

Set gfemap = GetObject(, “femap.model”)          ‘The open femap session

Set LoadSet = gfemap.feLoadSet                      ‘Set loadSet to a new femap feLoadSet object

Set Load = gfemap.feLoadMesh()                      ‘set load to a femap loadmesh object which will hold the

                                                                        ‘the force values at a particular node

‘ Create the new load set in femap

lLsetID = LoadSet.NextEmptyID                         ‘Get a unique ID for the loadset

LoadSet.Title = “Dummy LSet”                           ‘Name it

LoadSet.Put (lLsetID)                                       ‘Put it into Femap

‘loop through all the data on the worksheet

Do Until WS.Cells(iRow, 1) = “”

  lNID = WS.Cells(iRow, 1)                                ‘The node id for the force

  dFx = WS.Cells(iRow, 2)                                ‘The force values to apply at this node

  dFy = WS.Cells(iRow, 3)

  dFz = WS.Cells(iRow, 4)

  Load.meshID = lNID                                       ‘the node ID for this load

  Load.Type = 1                                               ‘load of type force

  Load.Load(0) = dFx                                       ‘set the force values

  Load.Load(1) = dFy

  Load.Load(2) = dFz

  Load.XOn = True                                           ‘make this dof active

  Load.YOn = True

  Load.ZOn = True

  Load.SetID = lLsetID                                      ‘attach this force to the loadset we created

  Load.Put (Load.NextEmptyID)                        ‘put the load into femap

  iRow = iRow + 1                                            ‘next row

Loop

End Sub

 

4) Do a regen in Femap and activate the loadset created, illustrated below:-