FreeForm Splitting VBA Macro Crashing on TFFormRecipe.Synchronize

Hello,

I'm trying to make a VBA macro to divide a FreeForm object to several FreeForms containing the same Family, Part, Symbology and Opening Features (i.e. dividing a FreeForm slab into several slabs). The idea is to select a bunch of 2D shapes along with a FreeForm object. The macro recognizes the FreeForm and adds the 2D shapes into an Array. Then it clones the FreeForm to the number of shapes, and changes the base of each FreeForm to the new shapes.

The first FreeForm comes out right with the new shape, but on the second loop (i=2), the tfForm.Synchronize crashes Bentley Architecture. I don't know what I'm doing wrong, since I'm not that advanced in Triforma VBA. Here's the complete code:

Option Explicit

Sub FreeFormChangeBase()

Dim tfFreeForm As TFFormRecipeFree
Dim tfPList As New TFPolyList
Dim tfP() As tfPoly
Dim ele As Element
Dim tfEleList As New TFElementList
Dim en As ElementEnumerator
Dim tfpCount As Integer
tfpCount = 0

Set tfFreeForm = TFApplication.CreateTFFormRecipeFree

'Find the freeform and the tfpoly (shape)
Set en = ActiveModelReference.GetSelectedElements
Debug.Print "------------------"
Debug.Print "Starting FreeForm Split App"
While en.MoveNext
    tfEleList.InitFromElement en.Current
    If tfEleList.AsTFElement.GetIsFormType Then
        Set ele = en.Current
        Debug.Print "Found FreeForm with id " & ele.id.Low
    Else
        tfPList.InitFromElement en.Current, 0.01
        tfpCount = tfpCount + 1
        ReDim Preserve tfP(tfpCount)
        'Set tfP(UBound(tfP)) = TFApplication.CreateTFPoly
        Set tfP(tfpCount) = tfPList.AsTFPoly
        Debug.Print "Found shape with id " & en.Current.id.Low
    End If
Wend

Debug.Print "Total polys found " & tfpCount

'Copy the source freeform and apply the new bases to them
Dim i As Integer
Dim tfForm As TFFormRecipe
For i = 1 To tfpCount
    
    tfEleList.InitFromElement ele.Clone
    tfEleList.AsTFElement.GetFormRecipeList tfFreeForm
    tfFreeForm.SetBase tfP(i)
    Set tfForm = tfFreeForm
    tfForm.Synchronize
    'TFApplication.ModelReferenceAddFormRecipe ActiveModelReference, tfForm
    TFApplication.ModelReferenceAddFormRecipeList ActiveModelReference, tfForm
    Debug.Print "Created new FreeForm with id " & tfForm.GetIdList.AsTFId.GetValueAssoc.Low
Next i

End Sub