COM Interface in VBA | 2.2 Creating Member

Technical Article

Part 2.1 of the article series about the COM interface described creating and modifying elements on an example of a member. In the third part, these core elements are used again to create nodal supports, loads, load combinations, and result combinations. Thus, the model created in the second part will be extended. Therefore, the elements explained in Part 1 and Part 2.1 are not described again.

Figure 01 - System

Get Interface of Opened Model

Unlike the last two articles, an existing model already opened in RFEM will be loaded now. In this example, the model from the second article is opened. First, the interface for the opened application is retrieved:

' Interface with RFEM is retrieved.
Dim iApp As RFEM5.Application
Set iApp = GetObject(, "RFEM5.Application")

Then, the error handler is started and the license is locked:

' Error Handler
On Error GoTo e

' COM license and program access is locked.

It is recommended to start the handler before locking the license, otherwise RFEM remains locked in the case of an error and can only be closed using Task Manager. Since the interface is now ready to be applied, you can get the interface for the model:

' Get interface for the first model.
Dim iModel As RFEM5.model
If iApp.GetModelCount > 0 Then
Set iModel = iApp.GetModel(0)
Err.Raise vbObjectError, "LoadModel()", "iApp.GetModelCount < 1"
End If

For better error handling, you can check whether the model is actually available (GetModelCount in this case) before retrieving the model. Even in the case of other interfaces, such as the interface for load cases or loads, you can indicate errors in a better way.

Creating Nodal Supports

A single‑span beam should be created and because the member is along the x‑axis, the x,y,z‑translation and the rotation about the x- and z‑axis has to be locked on Node 1 as well. The support on Node 2 is similar to the first one up to the free translation in the x‑direction. Before creating the nodal supports, it is still necessary to retrieve the interface for the model data. When defining the support, you should make sure that in the case of degrees of freedom, the number greater than or equal 0 is equalised with the release by using a spring constant. Here, the SI units are also used, that is N/m or N/rad:

' Get interface for model data.
Dim iModelData As RFEM5.iModelData
Set iModelData = iModel.GetModelData()

' Create nodal supports.
Dim nodsups(0 To 1) As RFEM5.NodalSupport
nodsups(0).No = 1
nodsups(0).nodeList = "1"
nodsups(0).RestraintConstantX = -1
nodsups(0).RestraintConstantY = 0#
nodsups(0).RestraintConstantZ = -1
nodsups(0).SupportConstantX = -1
nodsups(0).SupportConstantY = -1
nodsups(0).SupportConstantZ = -1

nodsups(1).No = 2
nodsups(1).nodeList = "2"
nodsups(1).RestraintConstantX = -1
nodsups(1).RestraintConstantY = 0#
nodsups(1).RestraintConstantZ = -1
nodsups(1).SupportConstantX = 0#
nodsups(1).SupportConstantY = -1
nodsups(1).SupportConstantZ = -1

If any problems occur, they may be caused by the wrong data type. If double is required, the integer entry may cause errors. Thus, it is necessary to add a hash key after the integer value, so that it is used as a double value.

Of course, the nodal support must then be transferred to the editing mode again (PrepareModification / FinishModification):

' Transfer nodal supports.
iModelData.SetNodalSupports nodsups

Create Load Cases

In order to create loads, you have to define load cases first, exactly like in RFEM. When programming, the load cases are created and transferred first, and only afterwards the loads can be transferred by using the interfaces of the load cases. First, we create the load cases:

' Get interface for loads.
Dim iLoads As RFEM5.iLoads
Set iLoads = iModel.GetLoads

' Create load cases.
Dim loadcases(0 To 2) As RFEM5.LoadCase

loadcases(0).Loading.No = 1
loadcases(0).SelfWeight = True
loadcases(0).ToSolve = True
loadcases(0).SelfWeightFactor.X = 0
loadcases(0).SelfWeightFactor.Y = 0
loadcases(0).SelfWeightFactor.Z = 1
loadcases(0).ActionCategory = Permanent

There are three load cases to be created: self‑weight, snow, and imposed load. In the COM programming, all identifiers are in English. Therefore, Permanent is used for ActionCategory in the case of the self‑weight load case. For the SelfWeightFactor property, you can set the direction and the self‑weight value. However, these apply only if the self‑weight property is set to True.

Furthermore, ToSolve must also be set to True in order to include the load case in the calculation and to assign a number to the load case (.Loading.No). The other two load cases are defined more easily as there is no self‑weight:

loadcases(1).Loading.No = 2
loadcases(1).SelfWeight = False
loadcases(1).ToSolve = True
loadcases(1).ActionCategory = ShowHLowerThan1000

loadcases(2).Loading.No = 3
loadcases(2).SelfWeight = False
loadcases(2).ToSolve = True
loadcases(2).ActionCategory = ImposedCategoryA

' Transfer load cases.
iLoads.SetLoadCases loadcases

The category ShowHLowerThan1000 is used for snow below an altitude of 1,000 m above sea level and ImposedCategoryA is used for the imposed load of Category A. Then, the load cases can be transferred to RFEM. However, the interface ILoads is used for this instead of the interface IModelData as the model data is not concerned anymore, but rather the load data is.

Create Load and Result Combinations

When creating either load or result combinations, there are only a few differences. The reason for this is that the calculation method and other settings can only be applied after creating the load combination via the corresponding interface. The definition is carried out as in RFEM. For this, you can use the identifier LC (Load Case). The different decimal separators and the uppercase and lowercase letters do not play any role and both are accepted:

' Create load combinations.
Dim loadcombs(0 To 0) As RFEM5.LoadCombination

loadcombs(0).Loading.No = 1
loadcombs(0).ToSolve = True
loadcombs(0).Definition = "1.35*lc1 + 1.5*lc2 + 1.05*lc3"

' Transfer load combinations.
iLoads.SetLoadCombinations loadcombs

' Create result combinations.
Dim rescombs(0 To 0) As RFEM5.ResultCombination

rescombs(0).Loading.No = 1
rescombs(0).Definition = "1.35*lc1 + 0.75*lc2 + 1.5*lc3"

' Transfer result combinations.
iLoads.SetResultCombinations rescombs

Creating Loads

As mentioned above, the loads will now be transferred using the interfaces for load cases. In our example, any additional loads are created in Load Case 1. In Load Case 2, a trapezoidal distributed load is applied. Load Case 3 applies a constant linear load and a nodal load. Here is the procedure for Load Case 2:

' Create loads.
' Load Case 2.
Dim iLoadCase As RFEM5.iLoadCase
Set iLoadCase = iLoads.GetLoadCase(2, AtNo)

Since we know the load case number, it can be used with AtNo when retrieving the interface:

' Create member loads.
Dim memLoads() As RFEM5.MemberLoad
ReDim memLoads(0 To 0)

In this case, the array is not dimensioned at the initialization, but afterwards, because memLoads should be used again for Load Case 3. This has the advantage that the content is reset to the default values when using ReDim again. Under ObjectList, you can select the members for loading, separated by commas or connected by hyphens. In addition to both load values for the load start (Magnitude1) and the load end (Magnitude2), the trapezoidal load requires the specification of distances for the load start (DistanceA) and end (DistanceB). The RelativeDistances property determines whether absolute (False) data in m or relative (True) data of 0‑1 will be used:

memLoads(0).No = 1
memLoads(0).ObjectList = "1"
memLoads(0).Distribution = TrapezoidalType
memLoads(0).Magnitude1 = 6000#
memLoads(0).Magnitude2 = 4000#
memLoads(0).RelativeDistances = False
memLoads(0).DistanceA = 0.2
memLoads(0).DistanceB = 0.9

' Transfer member loads.
iLoadCase.SetMemberLoads memLoads

When transferring the loads, the correct interface must be set, in this case the interface ILoadCase. The loads of Load Case 3 are defined similarly as follows:

' Create nodal loads.
Dim nodalLoads(0 To 0) As NodalLoad
nodalLoads(0).No = 1
nodalLoads(0).nodeList = "2"
nodalLoads(0).Component.Force.X = -15000
nodalLoads(0).Component.Force.Y = 0
nodalLoads(0).Component.Force.Z = 0
nodalLoads(0).Component.Moment.X = 0
nodalLoads(0).Component.Moment.Y = 0
nodalLoads(0).Component.Moment.Z = 0

' Transfer nodal loads.
iLoadCase.SetNodalLoads nodalLoads

' Create member loads.
ReDim memLoads(0 To 0)
memLoads(0).No = 1
memLoads(0).ObjectList = "1"
memLoads(0).Distribution = UniformType
memLoads(0).Magnitude1 = 5000#

' Transfer member loads.
iLoadCase.SetMemberLoads memLoads

When closing the program, the error handler routine is completed and the license is unlocked:

e: If Err.Number <> 0 Then MsgBox Err.Description, , Err.Source

' COM license is unlocked, the program access is possible again.

Summary and Overview

The procedures shown in the article are based on the two previous articles. As already mentioned there, the structure is similar for all elements. The mentioned exception of nonlinear member releases or nodal supports will be explained in the next article.



RFEM Main Program
RFEM 5.xx

Main Program

Structural engineering software for finite element analysis (FEA) of planar and spatial structural systems consisting of plates, walls, shells, members (beams), solids and contact elements

Price of First License
3,540.00 USD
RFEM Other
RF-COM 5.xx

Add-on Module

Programmable interface (API) based on the COM technology

Price of First License
580.00 USD