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

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button65.Click
Dim m_inventorApp As Inventor.Application = Nothing

' Try to get an active instance of Inventor
Try
m_inventorApp = System.Runtime.InteropServices.Marshal.GetActiveObject("Inventor.Application")
Catch ex As Exception
MsgBox(ex.Message)
End Try


' Create a transaction.
Dim oTransMgr As TransactionManager
oTransMgr = m_inventorApp.TransactionManager
Dim oTrans As Transaction
oTrans = oTransMgr.StartTransaction(m_inventorApp.ActiveDocument, "Replace hole")

Dim oSketch As PlanarSketch = Nothing
Dim oDoc As PartDocument
oDoc = m_inventorApp.ActiveDocument

' Set a reference to the component definition.
Dim oCompDef As PartComponentDefinition
oCompDef = oDoc.ComponentDefinition

Dim oHoles As HoleFeatures
oHoles = oDoc.ComponentDefinition.Features.HoleFeatures
Dim oHole As HoleFeature

For Each oHole In oHoles

oDoc.SelectSet.Clear()
oDoc.SelectSet.Select(oHole)

Dim oHoleCenter As Point
Dim oSketchPoint As SketchPoint

Dim oCollection As ObjectCollection
oCollection = m_inventorApp.TransientObjects.CreateObjectCollection

If TypeOf oHole.HoleCenterPoints.Item(1) Is SketchPoint Then
' Get the sketch point.
oSketchPoint = oHole.HoleCenterPoints.Item(1)

' Get the position of the sketch point in model space.
oSketch = oSketchPoint.Parent
oHoleCenter = oSketch.SketchToModelSpace(oSketchPoint.Geometry)


'Dim oSketchpoint As SketchPoint
For Each oSketchPoint In oHole.Sketch.SketchPoints
If oSketchPoint.HoleCenter Then
Call oCollection.Add(oSketchPoint)
End If
Next

'Löschen
oHole.Delete(True)
Call oCompDef.Features.HoleFeatures.AddDrilledByThroughAllExtent(oCollection, "10 mm", PartFeatureExtentDirectionEnum.kPositiveExtentDirection)

oDoc.Update()
Else

oHoleCenter = oHole.HoleCenterPoints.Item(1)
MsgBox(oHoleCenter.X & "; " & oHoleCenter.Y & "; " & oHoleCenter.Z)

' How to replace the hole without sketch?

End If

Next

oTrans.End()
End Sub

How could I replace the holes without sketch?