Showing results for 
Search instead for 
Do you mean 
Reply
Solved! Go to solution

Purge Group of all entities

[ Edited ]

I am trying to create a script that purges a specified group of all non-mesh entities and only leaves elements and nodes, but I seem to be having problems with the `RangeDeleteAll()` method. Here is my code:

 

Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim rc As Long

    Dim gr As femap.Group
    Set gr = App.feGroup

    Dim nodeSet As femap.Set
    Set nodeSet = App.feSet

    Dim elmSet As femap.Set
    Set elmSet = App.feSet

    ' Select group to purge
    rc = gr.SelectID("Select group to purge")
    If rc = FE_CANCEL Then
        Exit Sub
    End If

    'Retrieve nodes and elements
    Set nodeSet = gr.Range(FGD_NODE_ID)
    Set elmSet = gr.Range(FGD_ELEM_ID)

    'Purge all
    rc = gr.RangeDeleteAll(-1)

    'Add nodes and elements
    rc = gr.SetAdd(FT_NODE, nodeSet.ID)
    rc = gr.SetAdd(FT_ELEM, elmSet.ID)

End Sub

The RangeDeleteAll() method seems to return an FE_OK code, but doesn't actually do anything. Can someone tell me what's going on?

2 REPLIES
Solution
Solution
Accepted by topic author andyperez
‎05-24-2017 11:57 AM

Re: Purge Group of all entities

You need to Get and Put the group.  To do this, you need the group ID.   So in this case, instead of the gr.SelectID method you use, use App.feSet.SelectID method.

 

    ' Select group to purge
    Dim grID As Long
    rc = App.feSet.SelectID ( FT_GROUP, "Select Group to Purge", grID )
    If rc = FE_CANCEL Then
        Exit Sub
    End If

 

You also need to populate the sets differently:

 

The HTML Clipboard

     'Retrieve nodes and elements
    nodeSet.AddGroup ( FT_NODE, grID )
    elmSet.AddGroup ( FT_ELEM, grID )

The final API script should be something like this:

 

The HTML Clipboard

Sub Main
    Dim App As femap.model
    Set App = feFemap()

    Dim rc As Long

    Dim gr As femap.Group
    Set gr = App.feGroup

    Dim nodeSet As femap.Set
    Set nodeSet = App.feSet

    Dim elmSet As femap.Set
    Set elmSet = App.feSet

    ' Select group to purge
    Dim grID As Long
    rc = App.feSet.SelectID ( FT_GROUP, "Select Group to Purge", grID )
    If rc = FE_CANCEL Then
        Exit Sub
    End If

     'Retrieve nodes and elements
    nodeSet.AddGroup ( FT_NODE, grID )
    elmSet.AddGroup ( FT_ELEM, grID )

    gr.Get ( grID )

    'Purge all
    rc = gr.RangeDeleteAll(-1)

    'Add nodes and elements
    rc = gr.SetAdd(FT_NODE, nodeSet.ID)
    rc = gr.SetAdd(FT_ELEM, elmSet.ID)

    gr.Put ( grID )

    App.feViewRegenerate ( 0 )

End Sub

Best Regards,
Chip Fricke
Principal Applications Engineer - Femap Product Development

Re: Purge Group of all entities

That's perfect! Thanks, Chip!