Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpenUI
Imports NXOpen.Utilities
Module CylinderHoles
Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim lw As ListingWindow = s.ListingWindow
Dim wp As Part = s.Parts.Work
Sub Main()
Dim response1 As Integer = 0
Dim response2 As Selection.Response = Nothing
Dim mode1() As Integer = {0, 0}
Dim pointDisplayMode As Integer = 0
Dim pt1(2) As Double
Dim faceTag As Tag = Nothing
Dim holeDia As Double = 5.0
Dim parm(1) As Double
Dim facept(2) As Double
Dim u1(2) As Double
Dim v1(2) As Double
Dim junk3(2) As Double
Dim junk2(1) As Double
Dim n1(2) As Double
Dim holeobj1 As NXObject = Nothing
Dim bodyTag As Tag = Tag.Null
Dim cylbody As Body = Nothing
Start0:
holeDia = NXInputBox.GetInputNumber("Enter Hole Diameter", "Simple Hole on Cylinder", holeDia)
Start1:
response1 = select_a_face("Select the face", faceTag)
If response1 = Selection.Response.Back Then GoTo Start0
If response1 = Selection.Response.Cancel Then GoTo End1
Start2:
ufs.Ui.LockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
response2 = ufs.Ui.PointSubfunction("Select position", mode1, pointDisplayMode, pt1)
ufs.Ui.UnlockUgAccess(NXOpen.UF.UFConstants.UF_UI_FROM_CUSTOM)
If response2 = Selection.Response.Back Then GoTo Start1
If response2 = Selection.Response.Cancel Then GoTo End1
ufs.Modl.AskFaceParm(faceTag, pt1, parm, facept)
ufs.Modl.AskFaceProps(faceTag, parm, facept, u1, v1, junk3, junk3, n1, junk2)
ufs.Modl.AskFaceBody(faceTag, bodyTag)
cylbody = NXObjectManager.Get(bodyTag)
Dim point1 As Point3d = New Point3d(facept(0), facept(1), facept(2))
Dim pointObj As Point = wp.Points.CreatePoint(point1)
holeobj1 = SimpleHole1(wp, cylbody, pointObj, holeDia)
End1:
End Sub
Public Function mask_for_face(ByVal select_ As IntPtr, ByVal userdata As IntPtr) As Integer
Dim num_triples As Integer = 1
Dim mask_triples(0) As UFUi.Mask
mask_triples(0).object_type = UFConstants.UF_solid_type
mask_triples(0).object_subtype = 0
mask_triples(0).solid_type = UFConstants.UF_UI_SEL_FEATURE_ANY_FACE
ufs.Ui.SetSelMask(select_, _
UFUi.SelMaskAction.SelMaskClearAndEnableSpecific, _
num_triples, mask_triples)
Return UFConstants.UF_UI_SEL_SUCCESS
End Function
Public Function select_a_face(ByVal prompt As String, ByRef facetag As NXOpen.Tag) As Selection.Response
Dim resp As Integer = 0
Dim cp(2) As Double
Dim theView As NXOpen.Tag = NXOpen.Tag.Null
Dim mask_face As UFUi.SelInitFnT = AddressOf mask_for_face
ufs.Ui.LockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
ufs.Ui.SelectWithSingleDialog("Select a face", prompt, _
UFConstants.UF_UI_SEL_SCOPE_ANY_IN_ASSEMBLY, _
mask_face, Nothing, resp, facetag, cp, theView)
ufs.Ui.UnlockUgAccess(UFConstants.UF_UI_FROM_CUSTOM)
If resp = UFConstants.UF_UI_OBJECT_SELECTED Or _
resp = UFConstants.UF_UI_OBJECT_SELECTED_BY_NAME Then
Return resp
End If
Return resp
End Function
Function SimpleHole1(ByVal part1 As Part, ByVal body1 As Body, ByVal pointobj As Point, _
ByVal holedia As Double) As NXObject
Dim nullFeatures_HolePackage As Features.HolePackage = Nothing
Dim holePackageBuilder1 As Features.HolePackageBuilder
holePackageBuilder1 = part1.Features.CreateHolePackageBuilder(nullFeatures_HolePackage)
holePackageBuilder1.GeneralHoleForm = Features.HolePackageBuilder.HoleForms.Simple
holePackageBuilder1.GeneralSimpleHoleDiameter.RightHandSide = holedia
holePackageBuilder1.HoleDepthLimitOption = Features.HolePackageBuilder.HoleDepthLimitOptions.Value
holePackageBuilder1.GeneralSimpleHoleDepth.RightHandSide = "10"
holePackageBuilder1.Tolerance = 0.001
holePackageBuilder1.GeneralTipAngle.RightHandSide = "118"
Dim targetbodies1() As Body = {body1}
holePackageBuilder1.BooleanOperation.SetTargetBodies(targetbodies1)
holePackageBuilder1.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract
holePackageBuilder1.BooleanOperation.SetTargetBodies(targetbodies1)
Dim nullXform As Xform = Nothing
Dim point2 As Point
point2 = part1.Points.CreatePoint(pointobj, nullXform, SmartObject.UpdateOption.WithinModeling)
holePackageBuilder1.HolePosition.AddSmartPoint(point2, 0.001)
Dim nXObject2 As NXObject
nXObject2 = holePackageBuilder1.Commit()
Return nXObject2
End Function
Public Function GetUnloadOption(ByVal arg As String) As Integer
Return CType(Session.LibraryUnloadOption.Immediately, Integer)
End Function
End Module