Here is a sample , I have left in some comments so you can see how it is working. It gets rather complicated quickly with the need for proxies etc.
Approx Layout:
1. Occurence
2. PartDef
3. ProxyWorkPlane (Part)
4. AssemblySketch
5. SketchPoint(HoleCenter)
6. SketchHolePlacementDefinition
6. HoleFeature
Dim oAssyDef As AssemblyComponentDefinition = ThisDoc.Document.ComponentDefinition
Dim oCommandMgr As CommandManager = ThisApplication.CommandManager
Dim oOcc As ComponentOccurrence = oCommandMgr.Pick(SelectionFilterEnum.kAssemblyOccurrenceFilter, "Select Part Occurrence")
MessageBox.Show(oOcc.Name, "Occurrence Name")
Dim oPartDef As PartComponentDefinition = oOcc.Definition
' Select the plane we want to work with
Dim oWPlane1 As WorkPlane = oPartDef.WorkPlanes.Item("XZ PLANE")
' Need a proxy to identify where the workplane is located in assembly space.
Dim oWPlane1Proxy As WorkPlaneProxy
oOcc.CreateGeometryProxy(oWPlane1, oWPlane1Proxy)
'Dim oWorkPlaneProxy As WorkPlaneProxy = oCommandMgr.Pick(SelectionFilterEnum.kWorkPlaneFilter, "Select Part Workplane")
' Create a new sketch on the work plane proxy.
Dim oSketch As PlanarSketch = oAssyDef.Sketches.Add(oWPlane1Proxy)
'Dim oSketch As PlanarSketch = oCommandMgr.Pick(SelectionFilterEnum.kSketchObjectFilter, "Select Part Sketch")
' Create a new object collection for the hole center points.
oHoleCenters = ThisApplication.TransientObjects.CreateObjectCollection
Dim oPoint As Point = oPartDef.WorkPoints("Center Point").Point
' Set a reference to the transient geometry object.
Dim oTransGeom As TransientGeometry = ThisApplication.TransientGeometry
' Add a point as hole center.
oHoleCenters.Add (oSketch.SketchPoints.Add(oTransGeom.CreatePoint2d(oPoint.X-1, oPoint.Y)))
'oHoleCenters.Add(oSketch.SketchPoints(1))' Add from existing sketch
Dim oHoleFeatures As HoleFeatures = oAssyDef.Features.HoleFeatures
Dim oSketchHolePlacementDef As SketchHolePlacementDefinition = oHoleFeatures.CreateSketchPlacementDefinition(oHoleCenters)
Dim oHoleFeature As HoleFeature = oHoleFeatures.AddDrilledByThroughAllExtent(oSketchHolePlacementDef, 0.8, kNegativeExtentDirection)
If this solved a problem, please click (accept) as solution.
Or if this helped you, please, click (like)
Regards
Alan