<?xml encoding=”UTF-8″>By Xiaodong Liang
When you create hole feature, Inventor allows you to set the distances with the reference edges. This can be got by HoleFeature.PlacementDefinition.DistanceOne and HoleFeature.PlacementDefinition.DistanceTwo
If the reference are not defined, you could iterate the edges of outer edge loop and calculate the distance by Edge.Geometry.DistanceTo(point). The following is an VBA code as a demo:
Sub getHolePlacement()
'select a hole feature in advance
Dim oHoleF As HoleFeature
Set oHoleF = ThisApplication.ActiveDocument.SelectSet(1)
'get HolePlacementDefinition
Dim oPlaceDef As HolePlacementDefinition
Set oPlaceDef = oHoleF.PlacementDefinition
'reference are defined ?
Dim oDisOne As Parameter
Dim oDisTwo As Parameter
On Error Resume Next
Set oDisOne = oPlaceDef.DistanceOne
If Err.Number > 0 Then
'no distance defined
'get plane the hole locates at
Dim oPlane As Face
Set oPlane = oPlaceDef.Plane
'get out edge loop
Dim oOutLoop As EdgeLoop
Dim oEachLoop As EdgeLoop
For Each oEachLoop In oPlane.EdgeLoops
If oEachLoop.IsOuterEdgeLoop Then
Set oOutLoop = oEachLoop
Exit For
End If
Next
'iterate each edge and filter out the linear lines
Dim oEachEdge As Edge
For Each oEachEdge In oOutLoop.Edges
If TypeOf oEachEdge.Geometry Is LineSegment Then
Dim oLine As LineSegment
Set oLine = oEachEdge.Geometry
'caculate the distance of hole center and the edge
Dim oDis As Double
oDis = oLine.DistanceTo(oHoleF.HoleCenterPoints(1))
Dim oLineDir As UnitVector
Set oLineDir = oLine.Direction
Debug.Print "distance to the vector (" & oLineDir.X & "," & oLineDir.Y & "," & oLineDir.Z & ") is: " & oDis
End If
Next
Else
'distance are defined
Set oDisTwo = oPlaceDef.DistanceTwo
Debug.Print "distance one: " & oDisOne.Value & " distance two: " & oDisTwo.Value
End If
Err.Clear
End Sub


Leave a Reply