Yes, it is possible to export point coordinates from a sketch in CATIA V5, but not directly through a simple "export" command for the sketch itself. Sketch points are 2D entities within a 3D environment, so you typically need to convert them into 3D points or use a method that extracts their 3D location.
Here are several methods, ranging from manual to automated:
Method 1: Manual Extraction using "Measure Item" (For a Few Points)
This is the simplest way for a limited number of points.
- Activate the Sketch: Double-click on the sketch in the specification tree or directly in the graphic area to enter the Sketcher workbench.
- Exit Sketcher (Optional but Recommended): It's often easier to measure 3D points when outside the sketcher. If you've created explicit 3D points (see Method 2), you can measure them directly.
- Use "Measure Item":
- Go to
Tools > Measure > Measure Item (or click the tape measure icon).
- In the "Measure Item" dialog box, ensure "Selection Mode" is set to "Points" or "Any Geometry."
- Click on the point in your sketch that you want to get the coordinates for.
- The dialog box will display its X, Y, and Z coordinates relative to the active axis system.
- Copy Coordinates: You can manually copy these values from the "Measure Item" dialog box.
- Repeat: Repeat for each point.
Limitations: Tedious for many points.
Method 2: Create 3D Point Features from Sketch Points (For a Moderate Number of Points)
This method creates actual 3D point features which can then be used or measured.
- Activate your Part/Assembly: Ensure you are in a workbench like Part Design or Wireframe and Surface Design.
- Create Point:
- Go to
Insert > Wireframe > Point (or Insert > Point in Part Design).
- In the "Point Definition" dialog box:
- Set "Point type" to
On Plane or On Curve or simply Coordinates.
- If you click a sketch point directly: CATIA often automatically interprets this as "On Plane" and creates a 3D point at that location.
- Alternatively, if you're comfortable converting UV to XYZ manually, you could get the U,V coordinates from the sketch (visible when you select a point in the sketcher in the bottom-right status bar) and input them into a "Coordinates" point type, adjusting for the sketch plane's origin and orientation. However, clicking the sketch point is much easier.
- Repeat: Create a new 3D point feature for each desired sketch point.
- Export/Measure these 3D points:
- Once you have a set of 3D point features in your specification tree, you can select them one by one and use
Measure Item (as in Method 1) to get their coordinates.
- Alternatively, for a more bulk approach: You can export the CATPart as a format that might retain discrete points well, like some variations of IGES or STEP, but extracting pure XYZ from those files usually requires another CAD system or a specialized viewer.
- The best way to export multiple 3D points: Use a VBA macro (see Method 4).
Limitations: Still manual for creating the points, but results in explicit 3D geometry.
Method 3: Using "Projection" (Indirect, for specific scenarios)
This is less about direct export and more about creating new 3D points on a surface or plane based on sketch points.
- Create a Surface/Plane: Have a surface or plane in your 3D model where you want to project the sketch points onto.
- Use "Projection" Tool:
- Go to
Insert > Wireframe > Projection.
- Select your sketch as the "Projected" element.
- Select the surface/plane as the "Support."
- Choose a "Direction" (e.g., along Z-axis).
- Result: This will create new 3D curves and points on the target surface/plane. You can then use "Measure Item" or a macro on these projected points.
Limitations: Creates new geometry, not a direct export of the original sketch point coordinates. Useful if you need the points on a specific surface.
Method 4: VBA Macro (Most Efficient and Recommended for Many Points)
This is by far the most powerful and efficient method for exporting many point coordinates. It requires some basic programming knowledge in VBA (Visual Basic for Applications) within CATIA.
The macro would typically do the following:
- Select the Sketch: Prompt the user to select the sketch or identify it by name.
- Iterate through Sketch Elements: Loop through all geometric elements within the selected sketch.
- Identify Points: Check if an element is a point (or a vertex of a line, arc, etc.).
- Extract 3D Coordinates: For each point identified, retrieve its 3D coordinates relative to the global axis system. This often involves:
- Getting the point's U,V coordinates within the sketch.
- Getting the sketch's origin and axis directions in 3D space.
- Performing a transformation to convert the U,V coordinates to global X,Y,Z.
- Easier way for a macro: Create a temporary
HybridShapePointCoord object at the sketch point's location and then query its GetCoordinates method.
- Write to File: Write the X, Y, Z coordinates to a text file (e.g., a
.txt or .csv file).
Example VBA Macro Snippet (Conceptual - requires full context to run):
Sub ExportSketchPointCoordinates()
Dim CATIA As Object
Set CATIA = GetObject(, "CATIA.Application")
If CATIA Is Nothing Then Exit Sub
Dim partDocument As Object
Set partDocument = CATIA.ActiveDocument
If partDocument Is Nothing Then
MsgBox "No active document found.", vbCritical
Exit Sub
End If
If InStr(partDocument.Name, ".CATPart") = 0 Then
MsgBox "Please open a CATPart document.", vbCritical
Exit Sub
End If
Dim part As Object
Set part = partDocument.Part
Dim selection1 As Object
Set selection1 = partDocument.Selection
' User selects the sketch
MsgBox "Please select the Sketch you want to export points from."
selection1.Clear
Dim InputObjectType(0)
InputObjectType(0) = "Sketch"
status = selection1.SelectElement2(InputObjectType, "Select a Sketch", True)
If (status = "Cancel") Then
MsgBox "Sketch selection cancelled.", vbInformation
Exit Sub
End If
Dim selectedSketch As Object
Set selectedSketch = selection1.Item(1).Value
If Not TypeOf selectedSketch Is Sketch Then
MsgBox "The selected object is not a Sketch.", vbCritical
Exit Sub
End If
Dim sketchElements As Object
Set sketchElements = selectedSketch.GeometricElements
Dim outFile As Integer
outFile = FreeFile
Dim filePath As String
filePath = CATIA.FileSelectionBox("Save Points as CSV", "*.csv", CatFileSelectionModeSave)
If filePath = "" Then
MsgBox "File save cancelled.", vbInformation
Exit Sub
End If
Open filePath For Output As #outFile
Print #outFile, "Point Index,X,Y,Z" ' Header
Dim pointCounter As Integer
pointCounter = 0
Dim hybFactory As Object
Set hybFactory = part.HybridShapeFactory
Dim hybridBody As Object
' Create a temporary HybridBody to store temporary points (optional, good practice)
' This prevents cluttering the main body with calculation points.
' Or just do calculations without creating visible points.
On Error Resume Next ' In case HybridBodies container doesn't exist
Set hybridBody = part.HybridBodies.Item("TempPointsExport")
If Err.Number <> 0 Then
Set hybridBody = part.HybridBodies.Add()
hybridBody.Name = "TempPointsExport"
End If
On Error GoTo 0 ' Reset error handling
Dim tempPoint As Object
Dim coords(2) As Double
' Iterate through the geometric elements within the sketch
For i = 1 To sketchElements.Count
Dim geoElement As Object
Set geoElement = sketchElements.Item(i)
' Check if the element is a point or a vertex of a line/curve
If TypeOf geoElement Is Point2D Or TypeOf geoElement Is Line2D Or TypeOf geoElement Is Circle2D Or TypeOf geoElement Is Spline2D Then
' This part is tricky: How to get the 3D coordinates from a 2D sketch element.
' The easiest robust way is to create a temporary 3D point *from* the 2D sketch element
' and then query its 3D coordinates.
On Error Resume Next ' To handle cases where some sketch elements don't directly yield points
' For a direct Point2D
If TypeOf geoElement Is Point2D Then
Set tempPoint = hybFactory.AddNewPointCoord(0, 0, 0)
tempPoint.SetCoordWithReference geoElement
tempPoint.GetCoordinates coords
pointCounter = pointCounter + 1
Print #outFile, pointCounter & "," & coords(0) & "," & coords(1) & "," & coords(2)
tempPoint.Remove
' For vertices of lines/arcs/splines, you'd need to extract start/end points
' This is more complex and depends on which 'points' you want from curves.
' For simplicity, this example only handles explicit Point2D objects.
' For example, for a Line2D, you'd need to get its StartPoint and EndPoint.
' For a Spline2D, you might need to iterate through its control points or sample points.
' This snippet focuses on explicit Point2D objects within the sketch.
End If
On Error GoTo 0
End If
Next
Close #outFile
' Clean up the temporary HybridBody if it was created just for this export
' If hybFactory.Parent.Name = "TempPointsExport" Then hybFactory.Parent.Remove
MsgBox pointCounter & " points exported to: " & filePath, vbInformation
End Sub
How to use a VBA macro:
- Open CATIA.
- Press
Alt + F11 to open the VBA editor.
- In the VBA editor, right-click on your
CATPart (e.g., CATPart1 (CATPart1.CATPart)) in the Project Explorer and go to Insert > Module.
- Paste the code into the new module.
- Modify the code as needed (e.g., to handle specific types of sketch elements like vertices of lines/arcs if you need those).
- Go back to CATIA,
Tools > Macro > Macros... (or Alt + F8).
- Select
ExportSketchPointCoordinates and click Run.
- Follow the prompts.
Which method to choose?
- Few points (1-10): Use Method 1 (Measure Item). Quick and easy.
- Moderate points (10-50): Consider Method 2 (Create 3D Point Features) then measure manually, or transition directly to a macro.
- Many points (50+): Method 4 (VBA Macro) is the only practical and efficient solution.
The key challenge with sketch points is that they are intrinsically 2D relative to their sketch plane. To get 3D coordinates, you always need to account for the sketch plane's position and orientation in the global 3D space, which the Measure Item command and VBA macros handle automatically.