Start / End Hole Position

Below is code showing START hole coordinate (x,y,z). Is it possible to find END hole coordinate(x,y,z) when the depth limit of hole is Through Body?

I use NX 10

Option Strict Off
Imports System
Imports NXOpen
Imports System.Collections.Generic
Imports NXOpen.Features
Imports NXOpen.UF

Module Start_End_Hole_Position

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow

Dim featArray() As Feature = workPart.Features.GetFeatures()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start / End Hole Position")

theUfSession.Ui.ExitListingWindow()
lw.Open()

For Each myFeature As Feature In featArray
'lw.writeline(myFeature.FeatureType & " - " & myFeature.GetFeatureName)
If myFeature.FeatureType = "HOLE PACKAGE" Then

Dim holeFeature As HolePackage = myFeature
'lw.writeline(myFeature.GetFeatureName)

Dim holeDir() As Vector3d
holeFeature.GetDirections(holeDir)

Dim holeBuilder As HolePackageBuilder
holeBuilder = workPart.Features.CreateHolePackageBuilder(holeFeature)

'lw.WriteLine("hole type: " & holeBuilder.Type.ToString)

If holeBuilder.Type = HolePackageBuilder.Types.GeneralHole Then
lw.WriteLine("general hole form: " & holeBuilder.GeneralHoleForm.ToString)

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Simple Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralSimpleHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralSimpleHoleDepth.Value.ToString)
end if

lw.WriteLine("Start Location X: " & holeFeature.Location.X.ToString)
lw.WriteLine("Start Location Y: " & holeFeature.Location.Y.ToString)
lw.WriteLine("Start Location Z: " & holeFeature.Location.Z.ToString)

End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Counterbored Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCounterboreHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralCounterboreHoleDepth.Value.ToString)
end if

lw.WriteLine("counterbore diameter: " & holeBuilder.GeneralCounterboreDiameter.Value.ToString)
lw.WriteLine("counterbore depth: " & holeBuilder.GeneralCounterboreDepth.Value.ToString)

lw.WriteLine("Start Location X: " & holeFeature.Location.X.ToString)
lw.WriteLine("Start Location Y: " & holeFeature.Location.Y.ToString)
lw.WriteLine("Start Location Z: " & holeFeature.Location.Z.ToString)

End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Countersink Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCountersinkHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralCountersinkHoleDepth.Value.ToString)
end if

lw.WriteLine("countersink diameter: " & holeBuilder.GeneralCountersinkDiameter.Value.ToString)
lw.WriteLine("countersink angle: " & holeBuilder.GeneralCountersinkAngle.Value.ToString)

lw.WriteLine("Start Location X: " & holeFeature.Location.X.ToString)
lw.WriteLine("Start Location Y: " & holeFeature.Location.Y.ToString)
lw.WriteLine("Start Location Z: " & holeFeature.Location.Z.ToString)

End If

End If
lw.writeline("")
holeBuilder.Destroy()

End If

Next

lw.Close()

End Sub

End Module

Thanks

Here's a few things that I'd try:

If you have a prismatic part, you could get the faces from the hole feature and query the center points of the cylindrical hole face.

Whether you have a prismatic part or not, you could query the bounding box of the cylindrical face and calculate the depth.

Sorry, but I have no idea how to query the bounding box of the cylindrical face or get the faces from the hole feature and query the center points of the cylindrical hole face. Do you have any examples code which will be more helpfull?

The bounding box is great function which solved my issue. Now I don't need the end hole location but below is code finishing this topic.

Many thanks

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Imports NXOpen.UF

Module Start_End_Hole_Position

Sub Main()

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUFSession As UFSession = UFSession.GetUFSession
Dim lw As ListingWindow = theSession.ListingWindow

Dim featArray() As Feature = workPart.Features.GetFeatures()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start / End Hole Position")

theUfSession.Ui.ExitListingWindow()
lw.Open()

For Each myFeature As Feature In featArray

If myFeature.FeatureType = "HOLE PACKAGE" Then

Dim holeFeature As HolePackage = myFeature
'lw.writeline(myFeature.GetFeatureName)

Dim holeDir() As Vector3d
holeFeature.GetDirections(holeDir)

Dim holeBuilder As HolePackageBuilder
holeBuilder = workPart.Features.CreateHolePackageBuilder(holeFeature)

'lw.WriteLine("hole type: " & holeBuilder.Type.ToString)

Dim FaceType As Integer
Dim FacePoint(2) As Double
Dim FaceDir(2) As Double
Dim FaceBox(5) As Double
Dim FaceRadius As Double
Dim FaceRad_data As Double
Dim FaceNorm_dir As Integer

Dim csys As NXOpen.Tag = NXOpen.Tag.Null
Dim min_corner(2) As Double
Dim directions(2, 2) As Double
Dim distances(2) As Double

If holeBuilder.Type = HolePackageBuilder.Types.GeneralHole Then
lw.WriteLine("general hole form: " & holeBuilder.GeneralHoleForm.ToString)

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Simple Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralSimpleHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralSimpleHoleDepth.Value.ToString)
end if

lw.WriteLine("Start Location X: " & holeFeature.Location.X.ToString)
lw.WriteLine("Start Location Y: " & holeFeature.Location.Y.ToString)
lw.WriteLine("Start Location Z: " & holeFeature.Location.Z.ToString)

'lw.WriteLine("direction of first hole: " & holeDir(0).ToString)
'lw.writeline(myFeature.Tag)
Dim FeatureFace() As Tag
theUfSession.modl.AskFeatFaces(myFeature.Tag, FeatureFace)

For i As Integer = 0 to FeatureFace.Length-1

theUfSession.modl.AskFaceData(FeatureFace(i), FaceType, FacePoint, FaceDir, FaceBox, FaceRadius, FaceRad_data, FaceNorm_dir)
'lw.writeline("FaceDiameter: " & FaceRadius*2)
if FaceRadius.ToString = (holeBuilder.GeneralSimpleHoleDiameter.Value/2).ToString Then

theUfSession.Modl.AskBoundingBoxExact(FeatureFace(i), csys, min_corner, directions, distances)
if Math.Abs(holeDir(0).X) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X + distances(0) * holeDir(0).X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z)
End If

if Math.Abs(holeDir(0).Y) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y + distances(1) * holeDir(0).Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z)
End If

if Math.Abs(holeDir(0).Z) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z + distances(2) * holeDir(0).Z)
End If

End If
Next

End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Counterbored Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCounterboreHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption.ToString)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralCounterboreHoleDepth.Value.ToString)
end if

lw.WriteLine("counterbore diameter: " & holeBuilder.GeneralCounterboreDiameter.Value.ToString)
lw.WriteLine("counterbore depth: " & holeBuilder.GeneralCounterboreDepth.Value.ToString)

lw.WriteLine("Start Location X: " & holeFeature.Location.X.ToString)
lw.WriteLine("Start Location Y: " & holeFeature.Location.Y.ToString)
lw.WriteLine("Start Location Z: " & holeFeature.Location.Z.ToString)

'lw.writeline(myFeature.Tag)
Dim FeatureFace() As Tag
theUfSession.modl.AskFeatFaces(myFeature.Tag, FeatureFace)
'lw.writeline(FeatureFace.Length)

For i As Integer = 0 to FeatureFace.Length-1

theUfSession.modl.AskFaceData(FeatureFace(i), FaceType, FacePoint, FaceDir, FaceBox, FaceRadius, FaceRad_data, FaceNorm_dir)
'lw.writeline("FaceDiameter: " & FaceRadius*2)
if FaceRadius.ToString = (holeBuilder.GeneralCounterboreHoleDiameter.Value/2).ToString Then

'lw.writeline("FaceDiameter: " & FaceRadius*2)
theUfSession.Modl.AskBoundingBoxExact(FeatureFace(i), csys, min_corner, directions, distances)
if Math.Abs(holeDir(0).X) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X + (distances(0)+holeBuilder.GeneralCounterboreDepth.Value) * holeDir(0).X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z)
End If

if Math.Abs(holeDir(0).Y) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y + (distances(1)+holeBuilder.GeneralCounterboreDepth.Value) * holeDir(0).Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z)
End If

if Math.Abs(holeDir(0).Z) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z + (distances(2)+holeBuilder.GeneralCounterboreDepth.Value) * holeDir(0).Z)
End If

End If

Next

End If

If holeBuilder.GeneralHoleForm = HolePackageBuilder.HoleForms.Countersink Then
lw.WriteLine("hole diameter: " & holeBuilder.GeneralCountersinkHoleDiameter.Value.ToString)

if holeBuilder.HoleDepthLimitOption = holeBuilder.HoleDepthLimitOption.ThroughBody then
lw.WriteLine("hole depth: " & holeBuilder.HoleDepthLimitOption)
else
lw.WriteLine("hole depth: " & holeBuilder.GeneralCountersinkHoleDepth.Value.ToString)
end if

lw.WriteLine("countersink diameter: " & holeBuilder.GeneralCountersinkDiameter.Value.ToString)
lw.WriteLine("countersink angle: " & holeBuilder.GeneralCountersinkAngle.Value.ToString)

lw.WriteLine("Start Location X: " & holeFeature.Location.X.ToString)
lw.WriteLine("Start Location Y: " & holeFeature.Location.Y.ToString)
lw.WriteLine("Start Location Z: " & holeFeature.Location.Z.ToString)

'lw.writeline(myFeature.Tag)
Dim FeatureFace() As Tag
theUfSession.modl.AskFeatFaces(myFeature.Tag, FeatureFace)
'lw.writeline(FeatureFace.Length)

For i As Integer = 0 to FeatureFace.Length-1

theUfSession.modl.AskFaceData(FeatureFace(i), FaceType, FacePoint, FaceDir, FaceBox, FaceRadius, FaceRad_data, FaceNorm_dir)
'lw.writeline("FaceDiameter: " & FaceRadius*2)
if FaceRadius.ToString = (holeBuilder.GeneralCountersinkHoleDiameter.Value/2).ToString Then

theUfSession.Modl.AskBoundingBoxExact(FeatureFace(i), csys, min_corner, directions, distances)
if Math.Abs(holeDir(0).X) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X + (distances(0)+(holeBuilder.GeneralCountersinkDiameter.Value/2 - holeBuilder.GeneralCountersinkHoleDiameter.Value/2)) * holeDir(0).X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z)
End If

if Math.Abs(holeDir(0).Y) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y + (distances(1)+(holeBuilder.GeneralCountersinkDiameter.Value/2 - holeBuilder.GeneralCountersinkHoleDiameter.Value/2)) * holeDir(0).Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z)
End If

if Math.Abs(holeDir(0).Z) = 1 then
lw.WriteLine("End Location X: " & holeFeature.Location.X)
lw.WriteLine("End Location Y: " & holeFeature.Location.Y)
lw.WriteLine("End Location Z: " & holeFeature.Location.Z + (distances(2)+(holeBuilder.GeneralCountersinkDiameter.Value/2 - holeBuilder.GeneralCountersinkHoleDiameter.Value/2)) * holeDir(0).Z)
End If

End If

Next

End If

End If
lw.writeline("")
holeBuilder.Destroy()

End If

Next

lw.Close()

End Sub

End Module

Marcin