Variable hole size on cylinder
Variable hole size on cylinder
(OP)
I use NX6 to make a cylinder with a large amount of variable holes. After reading thread561-296588: Importing points from data file? i am able to create a series of 90 points on my cylinder. However the points does not show up in the "Part navigator". I have created some holes by manually selecting each point, but the problem is that the hole size vary, and its very much work specifying each hole diameter.
any tips?
any tips?





RE: Variable hole size on cylinder
Are the points coming from another part? Do you have WAVE?
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
CODE --> VB
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 ModuleFrank Swinkels
RE: Variable hole size on cylinder
X-cords Y-cords Z-cords Hole diameter?
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
Frank Swinkels
RE: Variable hole size on cylinder
http://files.engineering.com/getfile.aspx?folder=e...
again thank you very much.
RE: Variable hole size on cylinder
X Y Z d_hole
RE: Variable hole size on cylinder
CODE --> VB
Option Strict Off Imports System Imports System.IO Imports System.Windows.Forms 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 wp As Part = s.Parts.Work Sub Main() Dim response1 As Selection.Response = Nothing 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 junk3(2) As Double Dim junk2(1) As Double Dim holeobj1 As NXObject = Nothing Dim bodyTag As Tag = Tag.Null Dim cylbody As Body = Nothing Start1: response1 = select_a_face("Select the face", faceTag) If response1 = Selection.Response.Back Then GoTo End1 If response1 = Selection.Response.Cancel Then GoTo End1 Try Dim openFileDialog1 As New OpenFileDialog() openFileDialog1.Filter = "Data Files (*.dat)|*.dat|All files (*.*)|*.*" openFileDialog1.FilterIndex = 1 openFileDialog1.RestoreDirectory = True If openFileDialog1.ShowDialog() = DialogResult.OK Then Dim sr As StreamReader = New StreamReader(openFileDialog1.FileName) Dim linestring As String Dim testArray() As String Try Do While sr.Peek >= 0 linestring = sr.ReadLine If linestring.Length = 0 Then Exit Do testArray = Split(linestring, vbTab, 4) pt1(0) = CDbl(testArray(0)) pt1(1) = CDbl(testArray(1)) pt1(2) = CDbl(testArray(2)) holeDia = CDbl(testArray(3)) ufs.Modl.AskFaceParm(faceTag, pt1, parm, facept) ufs.Modl.AskFaceProps(faceTag, parm, facept, junk3, junk3, junk3, junk3, junk3, 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) Loop Finally sr.Close() End Try End If Catch E As Exception MessageBox.Show(E.Message) Exit Sub End Try 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) ufs.Disp.SetHighlight(facetag, 0) 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.ThroughBody 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 ModuleFrank Swinkels
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
holePackageBuilder1.HoleDepthLimitOption = Features.HolePackageBuilder.HoleDepthLimitOptions.ThroughBody and swapped "ThroughBody" with "value", and it worked, but how do i select the value? Also when i use "pointsfromfile.vb" from the other thread linked to, the points dont land on the same position as the holes from your journal, even though using the same coordinates for both journals...
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
You'll have to add the line:
CODE
holePackageBuilder1.GeneralHoleDepth.RightHandSide = <your value here>I'd add it after the line you changed, but I don't think it matters too much as long as it is after:
CODE
and before:
CODE
www.nxjournaling.com
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
CODE -->
Function CounterBoreHole1(ByVal part1 As Part, ByVal topbody1 As Body, ByVal point1 As Point, _ ByVal cboredia As Double, ByVal cboredepth As Double, _ ByVal cleardia 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.Counterbored holePackageBuilder1.GeneralCounterboreDiameter.RightHandSide = cboredia holePackageBuilder1.GeneralCounterboreDepth.RightHandSide = cboredepth holePackageBuilder1.GeneralCounterboreHoleDiameter.RightHandSide = cleardia holePackageBuilder1.HoleDepthLimitOption = Features.HolePackageBuilder.HoleDepthLimitOptions.ThroughBody holePackageBuilder1.Tolerance = 0.001 Dim targetbodies1() As Body = {topbody1} 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(point1, nullXform, SmartObject.UpdateOption.WithinModeling) point2.Layer = 255 ufs.Layer.SetStatus(255, 4) holePackageBuilder1.HolePosition.AddSmartPoint(point2, 0.001) Dim nXObject2 As NXObject nXObject2 = holePackageBuilder1.Commit() holePackageBuilder1.Destroy() holePackageBuilder1 = Nothing Return nXObject2 End FunctionThis fuction contains some additional code that for your application is not required but it shows the general code required. Now i dont know if you are trying to automate this which is certainly possible . It would require the dat file to have an input to identify the hole type and the hole data.
Frank Swinkels
RE: Variable hole size on cylinder
RE: Variable hole size on cylinder
I get the error "No face within tolerances", and if i try to increase the tollerance some of the holes change direction, so that they no longer are normal to the face. Its maybe easier to find a solution to this rather than editing the journal that works great as it is... I want to drill a series of holes with the same depth and diameter on top of the existing holes.
RE: Variable hole size on cylinder
Frank Swinkels
RE: Variable hole size on cylinder
x y z d_hole d_counterhole depth_counterhole
can i paste the function for cbore holes somewhere into the journal you made 1 Aug 12 8:21?
Also i get the error: "Line 1: Statement is not valid in a namespace."
RE: Variable hole size on cylinder
Frank Swinkels
RE: Variable hole size on cylinder