×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Variable hole size on cylinder
2

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?

RE: Variable hole size on cylinder

Can you show a picture, maybe a 2d sketch, of what the hole looks like?
Are the points coming from another part? Do you have WAVE?

RE: Variable hole size on cylinder

(OP)
the hole is just a simple hole, and the size vary between about 1-2,5mm. The points are coming from a .dat file created in excel. The points creates an uneven helix around the cylinder.

RE: Variable hole size on cylinder

(OP)
i also have the hole size in an excel file, and can create a .dat file with either just the hole size or the coordinates AND the hole size if that helps.

RE: Variable hole size on cylinder

Here is a journal to create a hole (fixed depth) on a cylinder face. It is a simple task to read the hole point and hole size from a data file.

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 Module 

Frank Swinkels

RE: Variable hole size on cylinder

(OP)
thank you very much! how do i specify the input?
X-cords Y-cords Z-cords Hole diameter?

RE: Variable hole size on cylinder

(OP)
am i doing anything wrong, or do you manually have to pick each hole size and position? My problem is that i might want to change hole size and position later, so i want to be able to just make a new data file and import that. Its not that much work to do one time, but if i want to change data and repeat, ill spend a lot of time just feeding NX data.

RE: Variable hole size on cylinder

Give me a dat file (with hole diameters) and a basic part and I will make the journal so that it reads the dat file for creating holes.

Frank Swinkels

RE: Variable hole size on cylinder

(OP)
btw. the format is:
X Y Z d_hole

RE: Variable hole size on cylinder

Here is the journal.

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 Module 


Frank Swinkels

RE: Variable hole size on cylinder

(OP)
Frank, youre a genious! thanks alot!!!

RE: Variable hole size on cylinder

(OP)
one more question though. the holes go through the cylinder on both sides. where in the code do i change the depth to a value?
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

(OP)
forget the last sentence. i messed up, using an old copy of the .dat file. sorry.

RE: Variable hole size on cylinder

Quote (magnusrm)

where in the code do i change the depth to a value?

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

holePackageBuilder1 = part1.Features.CreateHolePackageBuilder(nullFeatures_HolePackage) 

and before:

CODE

nXObject2 = holePackageBuilder1.Commit() 

www.nxjournaling.com

RE: Variable hole size on cylinder

(OP)
thank you. If i want to make counterbored holes what lines do i change, and how do i specify depth and diameter on counterboring?

RE: Variable hole size on cylinder

I use separate functions/subs for simple holes, counterbored holes, threaded holes etc. Here is a function I use for counterbored holes.

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 Function 

This 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

(OP)
ok, can i implement that code in the journal you already have made? How did you learn to make these journals? Any specific books or internet sites? I have only programmed basic HTML and MatLab, so this looks pretty messy to me. Do you use for most operations in NX?

RE: Variable hole size on cylinder

(OP)
I have a point at every hole, so it would be easy to do the counterboring part by just selectin every point and create a simple hole there, but NX wont let me.
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

Your method will not work. Why not create a counterbored hole as one feature? If I understand it you are creating a simple hole and then you want to create another simple hole to act as the counterbore? Either manually create a couterbored hole (as one feature) or in the datafile have the hole size and depth, counterbore size and counterbore depth OR simple hole diameter and depth if you have a mix of simple holes and counterbored holes for each line of data.

Frank Swinkels

RE: Variable hole size on cylinder

(OP)
The best would be to do what you say, to create a dat file with
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

2
Attached is a zip file which contains the journal to create counterbored holes. I have also included the modified dat file which includes values for the counterbores. Please note you need to change the value for the depth of the cbore hole (currently set at "10.0") to what you want.

Frank Swinkels

RE: Variable hole size on cylinder

(OP)
That worked. thanks alot! Very helpful for a fresh NX user. How do you recommend to learn to write journals?

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources