Dim oPart
Dim oGeometricalSetWithCreatedIntersection As HybridBody
Dim oSurface As HybridShape
Dim oLine As HybridShape
Dim oGeoSetWithLines As HybridBody
Set oPart = CATIA.ActiveDocument.Part
' Get All the Lines
Set oGeometricalSetWithCreatedIntersection = .............. ' Add the geoset to which you want your intersection to get appended
Set oGeoSetWithLines = ............ '- Add your code here
Set oSurface = ................... '- Add the surface to this variable
If Not oGeoSetWithLines.Count = 0 Then
For Each oLine In oGeoSetWithLines
CreateIntersection oSurface, oLine, oGeometricalSetWithCreatedIntersection
Next
End If
'--- Code
Sub CreateIntersection (obj1 As Object, obj2 As Object, oGeoSetToAppend As HybridBody)
If Not (obj Is Nothing) And (obj2 Is Nothing) Then
Dim bIntersectsWithEachOther As Boolean
bIntersectsWithEachOther = CheckIntersection (obj1, obj2)
If bIntersectsWithEachOther Then
call AddIntersection (obj1, obj2, oGeoSetToAppend)
End If
Else
MsgBox "One of the Item sent for creating intersection is missing",VbOKOnly,"Create Intersection Failed"
End If
End Sub
Sub AddIntersection (obj1 As Object, obj2 As Object, oAppendTo As HybridBody )
Dim ref1 As Reference
Set ref1 = oPart.CreateReferenceFromObject(input1)
Dim ref2 As Reference
Set ref2 = oPart.CreateReferenceFromObject(input2)
Dim new_int As HybridShapeIntersection
Set new_int = CurHSFactory.AddNewIntersection(ref1, ref2)
oAppendTo.AppendHybridShape new_int
oPart.UpdateObject new_int
End Sub
' CheckIntersection
Function CheckIntersection(Object1 As Variant, Object2 As Variant) As Boolean
On Error GoTo Blast
Dim TestInt As HybridShapeIntersection
Dim oSel As Variant
Set oSel = CATIA.ActiveDocument.Selection
Set TestInt = MyHSFactory.AddNewIntersection(Object1, Object2)
CATIA.ActiveDocument.Part.UpdateObject TestInt
CheckIntersection = True
' Delete the intersection otherwise it will get embedded into the document
' though user cant see this in tree until it gets appended to a Geometrical Set.
' later This can only be deleted from using CATDUA tool.
oSel.Clear
oSel.Add TestInt
oSel.Delete
oSel.Clear
Exit Function
Blast:
CheckIntersection = False
End Function