1860x
001408
2017-03-02

COM Interface in VBA | 2.2 Creating Member

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.


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.
iApp.LockLicense

We recommend starting the handler before locking the license; otherwise, RFEM remains locked in 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 first model.
Dim iModel As RFEM5.model
If iApp.GetModelCount > 0 Then
Set iModel = iApp.GetModel(0)
Else
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.

Create 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 around the x- and z‑axis have 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, a number greater than or equal to 0 is equalized 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.PrepareModification
iModelData.SetNodalSupports nodsups
iModelData.FinishModification

Create Load Cases

In order to create loads, you have to define load cases first, exactly as in RFEM. When programming, the load cases are created and transferred first, and only afterwards can the loads 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.PrepareModification
iLoads.SetLoadCases loadcases
iLoads.FinishModification

The ShowHLowerThan1000 category 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 ILoads interface is used for this instead of the IModelData interface, as the model data is no longer concerned; 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 a 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.PrepareModification
iLoads.SetLoadCombinations loadcombs
iLoads.FinishModification

' 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.PrepareModification
iLoads.SetResultCombinations rescombs
iLoads.FinishModification

Creating Loads

As mentioned above, the loads will now be transferred using the interfaces for load cases. In our example, no additional loads are created in Load Case 1; in Load Case 2, a trapezoidal distributed load is applied; and 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 with 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.PrepareModification
iLoadCase.SetMemberLoads memLoads
iLoadCase.FinishModification
When transferring the loads, the correct interface must be set; in this case, the ILoadCase interface. 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.PrepareModification
iLoadCase.SetNodalLoads nodalLoads
iLoadCase.FinishModification

' 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.PrepareModification
iLoadCase.SetMemberLoads memLoads
iLoadCase.FinishModification
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, program access is possible again.
iModel.GetApplication.UnlockLicense

Summary and Overview

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


Author

Mr. Günthel provides technical support for our customers.

Links
Downloads


;