Code:
Function FindElementFromConstraint(MyProduct As Product, o As Integer) As AxisSystemDim MySammler As Product
Dim MyConstraints As Constraints
Dim MyConstraint As Constraint
Dim MyReference1 As Reference
Dim MyReference2 As Reference
Dim MySelection As Selection
Dim i As Integer
Dim sSplit
Dim MyPartProd As Product
Dim MyPart As Part
Dim MyAxis As AxisSystem
Set MySammler = MyProduct.Parent.Parent
Set MyConstraints = MySammler.Connections("CATIAConstraints")
For i = 1 To MyConstraints.Count
If MyConstraints.Item(i).Type = 2 Then
Set MyConstraint = MyConstraints.Item(i)
Set MyReference1 = MyConstraint.GetConstraintElement(1)
Set MyReference2 = MyConstraint.GetConstraintElement(2)
If MyReference1 Is Nothing Or MyReference2 Is Nothing Then
Else
If InStr(1, MyReference1.DisplayName, "ADAPTER_POSITIONIERUNG", vbBinaryCompare) <> 0 And InStr(1, MyReference2.DisplayName, MyProduct.Name, vbBinaryCompare) <> 0 Then
Debug.Print MyReference1.DisplayName
Debug.Print MyReference2.DisplayName
sSplit = Split(MyReference1.DisplayName, "/")
Set MyPartProd = MyProduct.Parent.Parent.Products.GetItem(CStr(sSplit(1)))
Set MyPart = MyPartProd.ReferenceProduct.Parent.Part
Set MyAxis = MyPart.FindObjectByName(CStr(sSplit(UBound(sSplit))))
Set FindElementFromConstraint = MyAxis
Set MyOldReference(o) = MyReference1
ElseIf InStr(1, MyReference2.DisplayName, "ADAPTER_POSITIONIERUNG", vbBinaryCompare) <> 0 And InStr(1, MyReference1.DisplayName, MyProduct.Name, vbBinaryCompare) <> 0 Then
Debug.Print MyReference1.DisplayName
Debug.Print MyReference2.DisplayName
sSplit = Split(MyReference2.DisplayName, "/")
Set MyPartProd = MyProduct.Parent.Parent.Products.GetItem(CStr(sSplit(1)))
Set MyPart = MyPartProd.ReferenceProduct.Parent.Part
Set MyAxis = MyPart.FindObjectByName(CStr(sSplit(UBound(sSplit))))
Set FindElementFromConstraint = MyAxis
Set MyOldReference(o) = MyReference2
End If
End If
Set MyReference1 = Nothing
Set MyReference2 = Nothing
End If
Next
End Function