I am trying to search, select and delete all geometry (points, lines, ...) inside one specific sketch.
I can't find the right search command. It either selects all geometry of the entire part, which I don't want or nothing at all.
You need to select first the desired sketch, either by user choice or by searching after name and after that you need to search inside this selection the 2D geometry (with an advanced query you can select and delete whatever you want).
If you are still looking for answer try this code:
Sub CATMain()
Dim partDocument1 As PartDocument
Set partDocument1 = CATIA.ActiveDocument
Dim part1 As Part
Set part1 = partDocument1.Part
Dim hybridBodies1 As HybridBodies
Set hybridBodies1 = part1.HybridBodies
Dim hybridBody1 As HybridBody
Set hybridBody1 = hybridBodies1.Item("Geometrical Set.1")
Dim sketches1 As Sketches
Set sketches1 = hybridBody1.HybridSketches
Dim sketch1
Set sketch1 = sketches1.Item("Sketch.1")
Dim factory2D1 As Factory2D
Set factory2D1 = sketch1.OpenEdition()
Dim geometricElements1 As GeometricElements
Set geometricElements1 = sketch1.GeometricElements
While geometricElements1.Count > 1
If geometricElements1.Item(geometricElements1.Count).GeometricType <> catGeoTypeAxis2D Then
Dim Geometry2D
Set Geometry2D = geometricElements1.Item(geometricElements1.Count)
Set objHSF = part1.HybridShapeFactory
Set objRef = part1.CreateReferenceFromObject(Geometry2D)
objHSF.DeleteObjectForDatum objRef
End If
Wend
sketch1.CloseEdition
part1.Update
End Sub
But be careful, deleting all the geometry with the code will not delete the sketch! You cannot have a empty sketch in Catia. Leaving it empty can cause various problems.