The simple code below traverses the product tree. The
results are from running it using VBA, EKL VB Script, CATScript and
MS VBScript. The test product has 35473 nodes. VBA
runs in process and is compiled/tokenized to execute more
efficiently than interpreting the text line by line.
When running scripts from .NET it is always best to avoid
sending objects back to .NET to avoid boxing and unboxing COM
objects. But in .NET you can run CATIA processes in parallel which
cannot be done in any of the scripting frameworks.
Sub CollectProdObjIds_Test1()
Dim st As Single
Dim et As Single
st = Timer
Dim dic1 As Dictionary
Set dic1 = CreateObject("Scripting.Dictionary")
CollectProdObjIds CATIA.ActiveDocument.Product, dic1, "1"
et = Timer
Debug.Print "' VBA: " & et - st & " Ct: " & dic1.Count
' Product Ct: 35473
' ===================
' VBA:
' -----
' 0.2792969
' 0.2871094
' 0.2929688
' EKL VB Script:
' --------------
' 0.8564612
' 0.8398438
' 0.8554688
' CATScript:
' ----------
' 0.8066406
' 0.8984375
' 0.8652344
' MS VBScript:
' ------------
' 0.7265625
' 0.7460938
' 0.7187500
End Sub
Sub CollectProdObjIds(prod1 As Product, dic1 As Dictionary, k1
As String)
Dim prod2 As Product
Dim i As Long
Dim k2 As String
dic1.Add k1, prod1.Name
i = 0
For Each prod2 In prod1.Products
i = i + 1
k2 = k1 & "." & i
Call CollectProdObjIds(prod2, dic1, k2)
Next
End Sub
TomV
Boeing