834x
004688
2020-09-01

Question

How can I modify the FE mesh settings via the COM interface?


Answer:

The general FE mesh settings can be modified using the IFeMeshSettings interface. This interface is located under IModel > IModelData > ICalculation. Image 01 shows which elements can be modified / displayed.

Here is a code example where the target length of the FE elements is set to 100 mm. Furthermore, the division of the members with the same element size is activated and the minimum division is set to 3 elements:

Sub mesh_params()

Dim iApp As RFEM5.Application

'   get interface for model data
Dim iModel As RFEM5.model
Set iModel = GetObject(, "RFEM5.Model")

On Error GoTo e

If Not iModel Is Nothing Then
    
    '   get interface for application and lock licence
    Set iApp = iModel.GetApplication()
    iApp.LockLicense
    
    '   get interface for model dat
    Dim iModdata As RFEM5.IModelData2
    Set iModdata = iModel.GetModelData
    
    '   get interface for calculation
    Dim iCalc As RFEM5.ICalculation2
    Set iCalc = iModel.GetCalculation()
    
    '   get interface for mesh settings
    Dim iMeshSet As RFEM5.IFeMeshSettings
    Set iMeshSet = iCalc.GetFeMeshSettings
    
    '   get general mesh settings
    Dim meshGen As RFEM5.FeMeshGeneralSettings
    meshGen = iMeshSet.GetGeneral
    
    meshGen.ElementLength = 0.1
    
    '   set new general mesh settings
    iModdata.PrepareModification
    iMeshSet.SetGeneral meshGen
    iModdata.FinishModification
    
    '   get mesh member settings
    Dim meshMem As RFEM5.FeMeshMembersSettings
    meshMem = iMeshSet.GetMembers
    
    meshMem.DivideStraightMembers = True
    meshMem.ElementLength = 0.1
    meshMem.MinStraightMemberDivisions = 3
    
    '   set new mesh member settings
    iModdata.PrepareModification
    iMeshSet.SetMembers meshMem
    iModdata.FinishModification
    
    
    iApp.UnlockLicense
End If

e:  If Err.Number <> 0 Then
    MsgBox Err.description, , Err.Source
    End If
    iApp.UnlockLicense
    Set iApp = Nothing
    Set iModel = Nothing

End Sub


The subroutine is also completed by an error interception routine (On Error GoTo e), and the Prepare-/FinishModification block is required, as in the case of modifying other elements. Here, the block is created via the IFeMeshSettings interface.


Author

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