807x
004961
2021-04-08

Question

How can I use the COM interface to delete all nodes or members in a model, for example?


Answer:

To delete elements, there is the "DeleteObjects()" function in the model data interface. Deleting all members is then as follows:

Sub test_delete_objects()

Dim iApp As RFEM5.Application
Set iApp = GetObject(, "RFEM5.Application")

iApp.LockLicense

Dim iMod As RFEM5.IModel3
Set iMod = iApp.GetActiveModel


On Error GoTo e

    '   get interface for model data
    Dim iModData As RFEM5.IModelData2
    Set iModData = iMod.GetModelData
    
    '   get all members
    Dim mems() As RFEM5.Member
    mems() = iModData.GetMembers
    
    '   create member list
    Dim mem_list As String
    Dim i As Integer
    For i = 0 To UBound(mems, 1)
        mem_list = mem_list & mems(i).no & ","
    Next
    
    '   delete members
    iModData.PrepareModification
    iModData.DeleteObjects MemberObject, mem_list
    iModData.FinishModification
    
e:

If Err.Number <> 0 Then MsgBox Err.description, vbCritical, Err.Source

iMod.GetApplication.UnlockLicense
Set iMod = Nothing

End Sub


Please note that the "DeleteObjects" function only works with the object number and not with the object index. These numbers are transferred as a string, separated by commas.

For this reason, all members had to be fetched first. Then the member field was looped through and all member numbers were entered in the string.