Code:
Sub CATMain()Dim oProduct As Product
Set oProduct = CATIA.ActiveDocument.Product
Dim ParamWorks As Parameters
Set ParamWorks = oProduct.UserRefProperties
Dim oUserPropertyPosNo As Parameter
Set oUserPropertyPosNo = getUserProperty(ParamWorks, "Pos.-Nr.")
If oUserPropertyPosNo Is Nothing Then
MsgBox "Eigenschaft nicht vorhanden"
Exit Sub
End If
Dim oPart As Part
Set oPart = CATIA.ActiveDocument.Part
Dim oRelations As Relations
Set oRelations = oPart.Relations
Dim oParameters As Parameters
Set oParameters = oPart.Parameters
Dim parameterSet1 As ParameterSet
Set parameterSet1 = oParameters.RootParameterSet.ParameterSets.GetItem("Parameter_Stueckliste").ParameterSets.GetItem("Bauteil-Info")
Dim oParameterPosNo As Parameter
Set oParameterPosNo = parameterSet1.DirectParameters.GetItem("Pos.-Nr.")
Dim StrParameterPosNo As Object
StrUserPropertyPosNo = oParameters.GetNameToUseInRelation(oParameterPosNo)
Dim oFormula As Formula
Set formula1 = oRelations.CreateFormula("", "", oUserPropertyPosNo, CStr(StrUserPropertyPosNo))
End Sub
Function getUserProperty(UserProperties As Parameters, ParameterName As String) As Parameter
Dim I As Integer
For I = 1 To UserProperties.Count
If Right(UserProperties.Item(I).Name, Len(ParameterName)) = ParameterName Then
Set getUserProperty = UserProperties.Item(I)
Exit Function
End If
Next
Set getUserProperty = Nothing
End Function