Hi all,
I'm writing a macro to create a few user properties and one of the properties must have a formula to get the material name.
When you add a material to a part, a parameter is created name "Material". You can can easily create a formula inside a user property (in this case a string property) to link the value to the "Material" parameter. That's for the context.
I'm able to create my user property (name it MATERIAL), I can recover the parameter object associated to it (let's say my part is named Part1, the parameter name will be Part1\Properties\MATERIAL).
So I have my parameter object stored in a variable named propMat, I have my product in which the relations are (oProd = CATIA.ActiveDocument.Product). I created a small sub to generate the formula and it's like this :
In the rest of my code I call it with CreateFormula propMat, oProd (I could probably use Call in front of this but it works anyway).
strMat is a string containing the name of the user property "MATERIAL".
The formula itself is created, I can see it with the debugger but it's not visible in the relations in the tree nor the parameters window and the value is empty. I tried using "'Matériau'" (I'm working on a french version but I plan to make it work on english where it should be "Material" and probably german and italian later).
So I tried "'Material'", "='Material'", "Material" but every time the value is empty in the formula.
If I create it manually the formula shows 'Material'. I don't understand where I'm wrong.
I'm writing a macro to create a few user properties and one of the properties must have a formula to get the material name.
When you add a material to a part, a parameter is created name "Material". You can can easily create a formula inside a user property (in this case a string property) to link the value to the "Material" parameter. That's for the context.
I'm able to create my user property (name it MATERIAL), I can recover the parameter object associated to it (let's say my part is named Part1, the parameter name will be Part1\Properties\MATERIAL).
So I have my parameter object stored in a variable named propMat, I have my product in which the relations are (oProd = CATIA.ActiveDocument.Product). I created a small sub to generate the formula and it's like this :
In the rest of my code I call it with CreateFormula propMat, oProd (I could probably use Call in front of this but it works anyway).
strMat is a string containing the name of the user property "MATERIAL".
Code:
Sub CreateFormula(oParam As Parameter, produit As Product)
Dim oRels As Relations
On Error Resume Next
Set oRels = produit.Relations
If Err.Number <> 0 Then
MsgBox "Impossible de récupérer l'ensemble des relations pour créer la formule."
Exit Sub
End If
If InStr(1, oParam.Name, strMat, vbBinaryCompare) <> 0 Then
oRels.CreateFormula "FormuleMat", "", oParam, "'Matériau'"
End If
End Sub
So I tried "'Material'", "='Material'", "Material" but every time the value is empty in the formula.
If I create it manually the formula shows 'Material'. I don't understand where I'm wrong.