Announcements
Attention for Customers without Multi-Factor Authentication or Single Sign-On - OTP Verification rolls out April 2025. Read all about it here.
Michael.Navara
in reply to: ralfmja

This is not an answer but topic to discuss.

 

I don't understand why you create some non-parametric base features if you want to create planar sketch. You can create sketch directly on part planar face.

Here is more compact sample how to do it. You can select multiple source faces for hole placement.

Sub Main()
    Dim asm As AssemblyDocument = ThisDoc.Document
    Dim targetFaceProxy As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kAllPlanarEntities, "Pick target face or work plane")

    Dim targetOccurrence As ComponentOccurrence = targetFaceProxy.ContainingOccurrence
    Dim targetTransformation As Matrix = targetOccurrence.Transformation
    targetTransformation.Invert()
    Dim targetPartDef As PartComponentDefinition = targetOccurrence.Definition
    Dim targetFace As Face = targetFaceProxy.NativeObject

    Dim holeCenters As New List(Of Point)
    Do
        Dim sourceFace As FaceProxy = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFacePlanarFilter, "Pick source face or press ESC to continue")
        If sourceFace Is Nothing Then Exit Do
        Dim sourceOccurrence As ComponentOccurrence = sourceFace.ContainingOccurrence
        Dim sourcePartDef As PartComponentDefinition = sourceOccurrence.Definition
        For Each edgeLoop As EdgeLoopProxy In sourceFace.EdgeLoops
            If edgeLoop.IsOuterEdgeLoop Then Continue For
            Dim tempWorkPoint As WorkPoint = sourcePartDef.WorkPoints.AddAtCentroid(edgeLoop.NativeObject, True)
            Dim holeCenterPoint As Point = tempWorkPoint.Point
            tempWorkPoint.Delete()
            holeCenterPoint.TransformBy(sourceOccurrence.Transformation)
            holeCenterPoint.TransformBy(targetTransformation)
            holeCenters.Add(holeCenterPoint)
        Next
    Loop While True

    'Create sketch with center points
    Dim sketch As PlanarSketch = targetPartDef.Sketches.Add(targetFace)

    For Each holeCenter As Point In holeCenters
        Dim holeCenter2d = sketch.ModelToSketchSpace(holeCenter)
        sketch.SketchPoints.Add(holeCenter2d, True)
    Next
End Sub