'Paste into Visual Basic
'Open a part
'Second geoset in the Part must contain the points (you can change this)
'Run the macro
'Macro will:
' -Loop through all points
' -Create XYZ parameters under the point
' -Create a formula for XYZ parameters so they equal the location
' -Create an annotation set and view parallel to the ZX plane (you can change this)
' -Create annotations for the coordinates
'If you move a point on surface, the annotation updates to the new point coordinates
'*If you run it twice it will put more parameters under the points
'*Had to comment out setting oPartProduct because an open part doesn't have an associated product...but it ran fine
Sub CATMain()
'Part declarations
Dim oPart As Part
Dim oPartDocument As PartDocument
Dim oPartProduct As Product
Dim oSelection As Selection
Dim oRelations As Relations
Dim oParameters As Parameters
Dim oOriginElements As OriginElements
Dim oXYPlane
Dim oYZPlane
Dim oZXPlane
Dim oGeoset As HybridBody
'Point declarations
Dim oPoint As Point
Dim oPointParameters As Parameters
Dim xParam As Length
Dim yParam As Length
Dim zParam As Length
Dim xFormula As Formula
Dim yFormula As Formula
Dim zFormula As Formula
'Annotation declarations
Dim oText As DrawingText
Dim oUserSurfaces As UserSurfaces
'Set part variables
Set oPart = CATIA.ActiveDocument.Part
Set oPartDocument = oPart.Parent
'Set oPartProduct = oPartDocument.Product
Set oSelection = oPartDocument.Selection
Set oRelations = oPart.Relations
Set oParameters = oPart.Parameters
Set oOriginElements = oPart.OriginElements
Set oXYPlane = oOriginElements.PlaneXY
Set oYZPlane = oOriginElements.PlaneYZ
Set oZXPlane = oOriginElements.PlaneZX
Set oGeoset = oPart.HybridBodies.Item(2)'Change number to match the location of your geoset
Set oUserSurfaces = oPart.UserSurfaces
'make an annotation set If there isn't one
Set oAnnotationSets = oPart.AnnotationSets
If oAnnotationSets.Count = 1 Then
Set oAnnotationSet = oAnnotationSets.Item(1)
Else
Set oAnnotationSet = oAnnotationSets.AddInAProduct(oPartProduct, "1")
oPart.UpdateObject oAnnotationSet
End If
Set oAnnotationFactory = oAnnotationSet.AnnotationFactory
'Create annotation View
oSelection.Clear
oSelection.Add oZXPlane 'Change the plane that is selected to put annotations on a different plane
CATIA.StartCommand "Front View"
Set oView = oAnnotationSet.TPSViews.Item(oAnnotationSet.TPSViews.Count)
oSelection.Clear
oView.Name = "View for point coordinates"
'Hide the annotation view frame
oPart.UpdateObject oAnnotationSet
oSelection.Clear
oSelection.Add oView
oSelection.VisProperties.SetShow catVisPropertyNoShowAttr
oSelection.Clear
'Loop through the points in the geoset
For I = 1 To oGeoset.HybridShapes.Count
'Get a point in the geoset
Set oPoint = oGeoset.HybridShapes.Item(I)
'Make XYZ parameters for point, under the point
oSelection.Clear
oSelection.Add oPoint
Set oPointParameters = oParameters.SubList(oPoint, True)
Set xParam = oPointParameters.CreateDimension("xCoord", "LENGTH", 0)
Set yParam = oPointParameters.CreateDimension("yCoord", "LENGTH", 0)
Set zParam = oPointParameters.CreateDimension("zCoord", "LENGTH", 0)
oSelection.Clear
'Make formulas so the parameters update when the point is moved
Set xFormula = oRelations.CreateFormula("xCoordRel", "", xParam, oPart.Parameters.GetNameToUseInRelation(oPoint) & "->coord(1)")
Set yFormula = oRelations.CreateFormula("yCoordRel", "", yParam, oPart.Parameters.GetNameToUseInRelation(oPoint) & "->coord(2)")
Set zFormula = oRelations.CreateFormula("zCoordRel", "", zParam, oPart.Parameters.GetNameToUseInRelation(oPoint) & "->coord(3)")
'Create dummy annotation
Set oRefPoint = oPart.CreateReferenceFromObject(oPoint)
Set oUserSurface = oUserSurfaces.Generate(oRefPoint)
Set oAnnotation = oAnnotationFactory.CreateEvoluateText(oUserSurface, 10, 10, 10, True)
oAnnotation.Text.Text = "X=a" & vbCrLf & "Y=b" & vbCrLf & "Z=c"
'Attribute link dummy annotation
Set oText = oAnnotation.Text.Get2dAnnot
oText.InsertVariable 11, 1, xParam
oText.InsertVariable 7, 1, yParam
oText.InsertVariable 3, 1, zParam
oText.ActivateFrame catRectangle
Next
oPart.UpdateObject oAnnotationSet
End Sub