If the hole or slot was created as a single feature, and not just one of many in a single feature, then there is another route that you could consider for finding the center point of the slot. I have seen (and likely participated in) multiple other forum discussions about similar goals in the past, and after searching within my custom iLogic snippets, I found an iLogic rule example in there which is related to this. I do not recall what other forum discussion this may be from, or if I authored some or all of it or not, but I will post the code here anyways, just as added reference and ideas. The code asks the user to select the 'feature' right up front (not just an Edge or Face), then starts digging into its geometry to identify it as a slot. Once that is determined, it uses the 'profile' edges to get their 'centroid', which would be at the center of the slot. Then it creates a WorkPoint at its top, and bottom center points. Then it creates a WorkAxis which passes through those WorkPoints. Then it extrudes a cylindrical surface around that center axis. I don't recall why all the work features and surface were used, but it may have been an 'alignment' project, where they will later be aligned with holes in another part in an assembly.
Sub Main
Dim oObj = ThisApplication.CommandManager.Pick(SelectionFilterEnum.kPartFeatureFilter, "Select an Extrude Cut Slot.")
If oObj Is Nothing OrElse (TypeOf oObj Is Inventor.ExtrudeFeature = False) Then Exit Sub
Dim oExtFeat As ExtrudeFeature = oObj
Dim oExtDef As ExtrudeDefinition = oExtFeat.Definition
If Not oExtDef.Operation = PartFeatureOperationEnum.kCutOperation Then
MsgBox("This is not a 'Cut' operation. Exiting code.", , "")
Exit Sub
End If
Dim oProfile As Inventor.Profile = oExtDef.Profile
Dim oEdges1, oEdges2 As EdgeCollection
Dim oSideFace As Face = oExtFeat.SideFaces.Item(1)
For Each oEdge As Edge In oSideFace.Edges
If oEdge.TangentiallyConnectedEdges.Count = 4 Then
If oEdges1 Is Nothing OrElse oEdges1.Count = 0 Then
oEdges1 = oEdge.TangentiallyConnectedEdges
Else
oEdges2 = oEdge.TangentiallyConnectedEdges
End If
End If
Next 'oEdge
Dim oCDef As ComponentDefinition = oExtFeat.Parent
Dim oWPts As WorkPoints = oCDef.WorkPoints
Dim oWPt1 As WorkPoint = oWPts.AddAtCentroid(oEdges1)
oWPt1.Visible = False
'oWPt1.Name = oExtFeat.Name & " Profile Center 1"
Dim oWPt2 As WorkPoint = oWPts.AddAtCentroid(oEdges2)
oWPt2.Visible = False
'oWPt2.Name = oExtFeat.Name & " Profile Center 2"
Dim oWAs As WorkAxes = oCDef.WorkAxes
Dim oWA As WorkAxis = oWAs.AddByTwoPoints(oWPt1, oWPt2)
oWA.AutoResize = False
oWA.SetSize(oWPt1.Point, oWPt2.Point)
'oWA.Name = oExtFeat.Name & " Center Axis"
'now create an extruded cylinder surface around the center axis that is 5mm dia.
Dim oWPlanes As WorkPlanes = oCDef.WorkPlanes
Dim oSketchPlane As WorkPlane = oWPlanes.AddByNormalToCurve(oWA, oWPt1)
Dim oToPlane As WorkPlane = oWPlanes.AddByNormalToCurve(oWA, oWPt2)
Dim oCylinderSketch As PlanarSketch = oCDef.Sketches.Add(oSketchPlane, False)
Dim oCenter As SketchPoint = oCylinderSketch.AddByProjectingEntity(oWPt1)
Dim oCircle As SketchCircle = oCylinderSketch.SketchCircles.AddByCenterRadius(oCenter, .5) 'understood as centimeters
Dim oCylProfile As Inventor.Profile = oCylinderSketch.Profiles.AddForSurface()
Dim oExtFeats As ExtrudeFeatures = oCDef.Features.ExtrudeFeatures
Dim oCylExtDef As ExtrudeDefinition = oExtFeats.CreateExtrudeDefinition(oCylProfile, PartFeatureOperationEnum.kSurfaceOperation)
oCylExtDef.SetFromToExtent(oSketchPlane, False, oToPlane, False)
Dim oCylExt As ExtrudeFeature = oExtFeats.Add(oCylExtDef)
oSketchPlane.Visible = False : oToPlane.Visible = False
'now update the document
Dim oDoc As Document = oCDef.Document
oDoc.Update
End Sub
Wesley Crihfield

(Not an Autodesk Employee)