A Simple Femap API Program Tutorial: to generate a rectangular patch of elements. This tutorial is basically a continuation  of tutorial 2 but we join up the nodes.

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

2) The code :-

Option Explicit

Private Sub CommandButton1_Click()

Dim gfemap As Object

Dim oNode As Object

Dim i As Integer

Dim J As Integer

Dim iNID As Integer  ‘Will be used to count the node ID

Dim dx As Double

Dim dy As Double

Dim dz As Double

Dim iIDarray(0 To 10, 0 To 10) As Integer

iNID = 1                                                     ‘Start the node IDs at 1

Set gfemap = GetObject(, “femap.model”)

Set oNode = gfemap.fenode

‘*****************************************************************

‘ Generate the Nodes as in Tutorial 2

‘ We need to generate the nodes befor the elements but also

‘ need to remember the node IDs – hence 2d array iIDarray

‘*****************************************************************

For i = 0 To 10

  For J = 0 To 10

    dx = i * 0.1                                          ‘Create some x,y values for are nodes

    dy = J * 0.1

    dz = 0.5

    oNode.X = dx                                       ‘Set the X,Y,Z properties of the femap node object

    oNode.y = dy

    oNode.z = dz

    oNode.ID = iNID                                   ‘Set the node ID

    oNode.Put (iNID)                                  ‘Put the node back into femap at this ID location

    ‘*****************************************************************

    ‘ Save the node IDs so we can generate the elements next step

    ‘*****************************************************************

    iIDarray(i, J) = iNID

    iNID = iNID + 1                                     ‘Increment the node ID

  Next J

Next i

‘*****************************************************************

‘ Generate the elements

‘*****************************************************************

Dim iEID As Integer                                  ‘Will be used to count the Element IDs

Dim oElem As Object

‘oElem to the femap element object

Set oElem = gfemap.feElem

iEID = 1

For i = 0 To 9

  For J = 0 To 9

     oElem.node(0) = iIDarray(i, J)                ‘Specify the nodes for the element

     oElem.node(1) = iIDarray(i, J + 1)          ‘with the node IDs we stored in

     oElem.node(2) = iIDarray(i + 1, J + 1)     ‘iIDarray during the node creation

     oElem.node(3) = iIDarray(i + 1, J)

     oElem.Type = 21                                   ‘The type for this element is laminate

     oElem.topology = 4                                ‘The topology is a 4 node quad

     oElem.PropID = 1                                  ‘The Property ID is 1 – which doest actually

                                                                 ‘exist so the element will be a plot only

     oElem.ID = iEID

     oElem.Put (iEID)

     iEID = iEID + 1

  Next J

Next i

End Sub

3) Exit design mode, press the command button and do a Femap regen. The nodes and elements should have been created as illustrated below:-

The next tutorial is a simple grep type utility for extracting lines from a text file. It could be used, for example, to strip  all the QUAD4 lines from a Nastran deck.