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 ExplicitSub FreeFormChangeBase()Dim tfFreeForm As TFFormRecipeFreeDim tfPList As New TFPolyListDim tfP() As tfPolyDim ele As ElementDim tfEleList As New TFElementListDim en As ElementEnumeratorDim tfpCount As IntegertfpCount = 0Set tfFreeForm = TFApplication.CreateTFFormRecipeFree'Find the freeform and the tfpoly (shape)Set en = ActiveModelReference.GetSelectedElementsDebug.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 IfWendDebug.Print "Total polys found " & tfpCount'Copy the source freeform and apply the new bases to themDim i As IntegerDim tfForm As TFFormRecipeFor 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.LowNext iEnd Sub
OK, problem is solved by turning tfEleList into an array instead of a single entity.