I have a macro that creates four points.
The Length of each point is linked to a parameter already set but just to create the point for first time.
I would like a full link, as example if the parameter has any update of value, the Length of each point should update accordingly.
If I double click on the point created via this code, I need to see
Length = value = CATIA_V5R22_VENT-HOLES-DEFINITION-BACKREST_V01\HOLES_PARAMETERS\HOLE_RADIUS
not like this
Length = value
Private Function GetParameterValue(part As Object, categoryName As String, parameterName As String) As Double
Dim parameters As Object
Dim parameter As Object
Set parameters = part.parameters
On Error Resume Next
Set parameter = parameters.Item(categoryName & "\" & parameterName)
If Not parameter Is Nothing Then
GetParameterValue = parameter.value
Else
GetParameterValue = 0 ' Default value if the parameter doesn't exist
End If
On Error GoTo 0
End Function
Sub points(hybridBody As Object)
Dim partDocument As Object
Set partDocument = CATIA.Documents.Item("CATIA_V5R22_VENT-HOLES-DEFINITION-BACKREST_V01.CATPart")
Dim part1 As Object
Set part1 = partDocument.part
' Retrieve the value of the hole radius
Dim holeRadius As Double
holeRadius = GetParameterValue(part1, "HOLES_PARAMETERS", "HOLE_RADIUS")
Dim hybridShapes1 As Object
Set hybridShapes1 = hybridBody.hybridShapes
Dim hybridShapeLinePtDir1 As Object
Set hybridShapeLinePtDir1 = hybridShapes1.Item("Horiz. Axis")
Dim reference1 As Object
Set reference1 = part1.CreateReferenceFromObject(hybridShapeLinePtDir1)
Dim hybridShapeIntersection1 As Object
Set hybridShapeIntersection1 = hybridShapes1.Item("Inter. Right")
Dim reference2 As Object
Set reference2 = part1.CreateReferenceFromObject(hybridShapeIntersection1)
Dim hybridShapeFactory1 As Object
Set hybridShapeFactory1 = part1.hybridShapeFactory
Dim hybridShapePointOnCurve1 As Object
Set hybridShapePointOnCurve1 = hybridShapeFactory1.AddNewPointOnCurveWithReferenceFromDistance(reference1, reference2, holeRadius, True)
hybridShapePointOnCurve1.distanceType = 1
hybridShapePointOnCurve1.Name = "Point.1"
hybridBody.AppendHybridShape hybridShapePointOnCurve1
part1.InWorkObject = hybridShapePointOnCurve1
part1.Update
part1.Update
End Sub
You have to get the .Offset
parameter of the hybridShapePointOnCurve
and create a formula using CreateFormula
.
Example:
'get Parameterset
Set oParameters = part1.Parameters
Set oParameterSet = oParameters.RootParameterSet.ParameterSets.Item("HOLES_PARAMETERS")
'get radius parameter
Set oParameterRadius = oParameterSet.DirectParameters.Item("HOLE_RADIUS")
'create formula
Set oRelations = part1.Relations
Set oParameterOffset = hybridShapePointOnCurve1.Offset
Set oFormula = oRelations.CreateFormula("","", oParameterOffset, oParameters.GetNameToUseInRelation(oParameterRadius))