Hello. I've created a CATVBA program that finds all the edges of a surface and then joins them together. The problem is if there are 700 edges (a medium sized part) then it takes 5 - 10 minutes for the macro to run as it adds all the edges one by one. Is there any way to increase the speed so it runs faster? Most of my code is shown below:
Code:
Sub CATMain()
Dim colDocum As Documents
Dim DocActivo As Document
Dim part1 As Part
Dim colBodies As Bodies
Dim hSFact As Factory
Dim colHBody As HybridBodies
Dim OpenBody1 As HybridBody
Dim sStatus As String
Dim MySelection As Selection
Dim InputObjectType(0)
InputObjectType(0) = "HybridShapeAssemble"
Dim refBorde As Reference
Set DocActivo = CATIA.ActiveDocument
Set part1 = DocActivo.Part
Set MySelection = DocActivo.Selection
Set hSFact = part1.HybridShapeFactory
Set colBodies = part1.Bodies
Dim dummy
Set dummy = MySelection
Dim Result As String
Result = dummy.SelectElement2(InputObjectType, "Select a face", False)
If (sStatus = "Cancel") Then
Exit Sub
End If
Set refBorde = MySelection.Item(1).Value
Dim hybridShapeExtract1 As HybridShapeExtract
Set hybridShapeExtract1 = hSFact.AddNewExtract(refBorde)
hybridShapeExtract1.PropagationType = 3
hybridShapeExtract1.ComplementaryExtract = False
hybridShapeExtract1.IsFederated = False
Set refBorde = hybridShapeExtract1
hybridShapeExtract1.Name = "Extracted_Face"
''''' Create Open Body
Dim HB1 As HybridBodies
Set HB1 = CATIA.ActiveDocument.Part.HybridBodies
Dim Hierarchie1, ImKoerper As HybridBody
Set Hierarchie1 = HB1.Add
Hierarchie1.Name = "Extracted_Elements"
''''''''
Set colHBody = part1.HybridBodies
Set OpenBody1 = part1.InWorkObject
OpenBody1.AppendHybridShape hybridShapeExtract1
part1.InWorkObject = hybridShapeExtract1
part1.Update
dummy.Clear
dummy.Add hybridShapeExtract1
Dim partDocument1 As Document
Set partDocument1 = CATIA.ActiveDocument
Dim selection1 As Selection
Set selection1 = partDocument1.Selection
selection1.Search "Topology.CGMEdge,sel"
MsgBox selection1.Count2 & " Edges are found from the selected face"
Dim HSF1 As HybridShapeFactory
Set HSF1 = part1.HybridShapeFactory
Dim myedge
Dim myEdge2
Dim myEdgeRef As Reference
Dim myEdgeRef2 As Reference
'--if only one surface
If selection1.Count = 1 Then
Set myedge = selection1.Item(1)
Set myEdgeRef = myedge.Reference
Dim hybridShapeAssemble1 As HybridShapeAssemble
Set hybridShapeAssemble1 = HSF1.AddNewJoin(myEdgeRef, myEdgeRef)
OpenBody1.AppendHybridShape hybridShapeAssemble1
part1.InWorkObject = hybridShapeAssemble1
part1.Update
hybridShapeAssemble1.RemoveElement 2
Else
'---if exactly two surfaces------------
Set myedge = selection1.Item(1)
Set myEdge2 = selection1.Item(2)
Set myEdgeRef = myedge.Reference
Set myEdgeRef2 = myEdge2.Reference
Set hybridShapeAssemble1 = HSF1.AddNewJoin(myEdgeRef, myEdgeRef2)
hybridShapeAssemble1.SetConnex 0
hybridShapeAssemble1.SetManifold 0
hybridShapeAssemble1.SetSimplify 0
hybridShapeAssemble1.SetSuppressMode 0
hybridShapeAssemble1.SetDeviation 0.001
hybridShapeAssemble1.SetAngularToleranceMode 0
hybridShapeAssemble1.SetAngularTolerance 0.5
hybridShapeAssemble1.SetFederationPropagation 0
OpenBody1.AppendHybridShape hybridShapeAssemble1
part1.InWorkObject = hybridShapeAssemble1
part1.Update
'join complete if only 2 surfaces
'if more than 3 surfaces, need to add each surface one by one
If selection1.Count > 2 Then
Dim i As Integer
For i = 3 To selection1.Count
Set myedge = selection1.Item(i)
Set myEdgeRef = myedge.Reference
hybridShapeAssemble1.AddElement myEdgeRef
Next
Else
End If
End If
hybridShapeAssemble1.Name = "EdgeJoin"
selection1.Clear
part1.Update
MsgBox "JOIN Success!"
End