"Unofficial CATIA User Forum"で、ここなさんが記載していた
マクロの高速化のソースコードが手元に残っていたので、
これを利用してマクロの実行速度のテストをして見たいと思います。
(ソースコードは、完全にオリジナルのものではないかもしれません)
'VBA Private Declare Function timeGetTime Lib "winmm.dll" () As Long Sub CATMain() Dim T As Long T = timeGetTime Call SubCreateDatumPoint MsgBox CDbl(timeGetTime - T) / 1000 & "秒" End Sub Private Sub SubCreateDatumPoint() Dim oPart As MECMOD.Part Dim oHybShpFact As HybridShapeTypeLib.HybridShapeFactory Dim oHybBdy As MECMOD.HybridBody Dim oHybShpPt 'As HybridShapeTypeLib.HybridShapePointCoord Dim oHybShpPtExp As HybridShapeTypeLib.HybridShapePointExplicit Dim i As Integer Dim oPt As Variant Dim colMyObj1 As Collection Dim oMyobj As Object Set oPart = CATIA.ActiveDocument.Part Set oHybShpFact = oPart.HybridShapeFactory Set colMyObj1 = New Collection '------------ Add Body ------------------------------ Set oHybBdy = oPart.HybridBodies.add() '------------ Create RefPoint ------------------------------ oPt = Array(0, 0, 0) Set oHybShpPt = oHybShpFact.AddNewPointCoord(oPt(0), oPt(1), oPt(2)) Call oHybBdy.AppendHybridShape(oHybShpPt) Call oPart.UpdateObject(oHybShpPt) '------------ Create DetumPoints ------------------------------ For i = 1 To 500 oPt(0) = oPt(0) + 10 Call oHybShpPt.SetCoordinates(oPt) Call oPart.UpdateObject(oHybShpPt) Set oHybShpPtExp = oHybShpFact.AddNewPointDatum(oHybShpPt) Call colMyObj1.add(oHybShpPtExp) Next '------------ Append DetumPoints ------------------------------ With oHybBdy For Each oMyobj In colMyObj1 Call .AppendHybridShape(oMyobj) Next End With Call oHybShpFact.DeleteObjectForDatum(oHybShpPt) 'Delete RefPoint Call oPart.Update Set colMyObj1 = Nothing End Sub
内容的には、点のインスタンスを1つ作り、X座標を10mm変更しながらデータム化し
最後にまとめて形状セットに入れていますね。
VBAをアウトプロセスで実行する環境が無いため、VBAに関してはインプロセスで
時間を測定しますが、インプロセスもVBエディタから実行した場合と
ツールバーに登録し実行した場合で速度が大きく異なります。
(試す事ができないのですが、経験的にアウトプロセスは遅いです)
CATIAの再起動も面倒なため、Partファイルのみを新作し実行した結果
○インプロセス-VBエディタ
1回目:6.182秒
2回目:6.211秒
3回目:6.240秒
○インプロセス-ツールバー
1回目:1.624秒
2回目:1.622秒
3回目:1.730秒