Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations Ron247 on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hole Edit Journal, NX9

Status
Not open for further replies.

3dr

Automotive
Jul 10, 2004
456
I've made a template file with a hole feature. It's always Feature (26)
I want to be able to switch it from Cbore to Csink to Simple.

The Journals I've made do it well in the seed file. But after cloning it into an assembly it doesn't work.
I'm sure it's because it's not the same file anymore.

How can I make this universal to any file with this feature?

TIA for any help



' NX 9.0.2.5
' Journal created by Dave on Tue Oct 27 06:06:17 2015 Eastern Daylight Time
'
Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Edit Feature Parameters")

Dim holePackage1 As Features.HolePackage = CType(workPart.Features.FindObject("COUNTERBORED SCREW HOLE(26)"), Features.HolePackage)

Try
' Invalid feature.
holePackage1.SetGroupActive(True)
Catch ex As NXException
ex.AssertErrorCode(670060)
End Try

Dim markId2 As Session.UndoMarkId
markId2 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Start")


If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

Dim holePackageBuilder1 As Features.HolePackageBuilder
holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(holePackage1)

holePackageBuilder1.StartHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract

Dim targetBodies1(0) As Body
Dim nullBody As Body = Nothing

targetBodies1(0) = nullBody
holePackageBuilder1.StartHoleData.BooleanOperation.SetTargetBodies(targetBodies1)

holePackageBuilder1.MiddleHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract

Dim targetBodies2(-1) As Body
holePackageBuilder1.MiddleHoleData.BooleanOperation.SetTargetBodies(targetBodies2)

holePackageBuilder1.EndHoleData.BooleanOperation.Type = GeometricUtilities.BooleanOperation.BooleanType.Subtract

Dim targetBodies3(0) As Body
targetBodies3(0) = nullBody
holePackageBuilder1.EndHoleData.BooleanOperation.SetTargetBodies(targetBodies3)

Dim targetBodies4(0) As Body
Dim body1 As Body = CType(workPart.Bodies.FindObject("EXTRUDE(3)"), Body)

targetBodies4(0) = body1
holePackageBuilder1.BooleanOperation.SetTargetBodies(targetBodies4)

holePackageBuilder1.HolePosition.PrepareMappingData()

holePackageBuilder1.ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Counterbored

theSession.SetUndoMarkName(markId2, "Hole Dialog")

holePackageBuilder1.HolePosition.DistanceTolerance = 0.0004

holePackageBuilder1.HolePosition.ChainingTolerance = 0.00038

holePackageBuilder1.ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Countersink

holePackageBuilder1.ScrewClearanceCountersinkDiameter.RightHandSide = "0.762"

holePackageBuilder1.ScrewClearanceReliefDepth.RightHandSide = "0.06"

Dim markId3 As Session.UndoMarkId
markId3 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Hole")

theSession.DeleteUndoMark(markId3, Nothing)

Dim markId4 As Session.UndoMarkId
markId4 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Hole")

holePackageBuilder1.ScrewType = "Machine (82 degree)"

holePackageBuilder1.StartHoleData.ScrewType = "Socket Head, 4762"

holePackageBuilder1.StartHoleData.ScrewSize = "M1.6"

holePackageBuilder1.StartHoleData.FitOption = "Close (H12)"

holePackageBuilder1.MiddleHoleData.FitOption = "Close (H12)"

holePackageBuilder1.EndHoleData.FitOption = "Close (H12)"

Dim nXObject1 As NXObject
nXObject1 = holePackageBuilder1.Commit()

theSession.DeleteUndoMark(markId4, Nothing)

theSession.SetUndoMarkName(markId2, "Hole")

holePackageBuilder1.HolePosition.CleanMappingData()

Dim expression1 As Expression = holePackageBuilder1.DrillSizeTipAngle

Dim expression2 As Expression = holePackageBuilder1.DrillSizeStartChamferOffset

Dim expression3 As Expression = holePackageBuilder1.DrillSizeStartChamferAngle

Dim expression4 As Expression = holePackageBuilder1.DrillSizeEndChamferOffset

Dim expression5 As Expression = holePackageBuilder1.DrillSizeEndChamferAngle

Dim expression6 As Expression = holePackageBuilder1.DrillSizeHoleDiameter

Dim expression7 As Expression = holePackageBuilder1.ScrewClearanceReliefDepth

Dim expression8 As Expression = holePackageBuilder1.ScrewClearanceNeckChamferOffset

Dim expression9 As Expression = holePackageBuilder1.ScrewClearanceNeckChamferAngle

Dim expression10 As Expression = holePackageBuilder1.ScrewClearanceCountersinkDiameter

Dim expression11 As Expression = holePackageBuilder1.ScrewClearanceCountersinkAngle

Dim expression12 As Expression = holePackageBuilder1.GeneralCounterboreDiameter

Dim expression13 As Expression = holePackageBuilder1.GeneralCounterboreDepth

holePackageBuilder1.Destroy()

theSession.DeleteUndoMark(markId2, Nothing)

Dim holePackage2 As Features.HolePackage = CType(nXObject1, Features.HolePackage)

holePackage2.SetGroupActive(False)

theSession.Preferences.Modeling.UpdatePending = False

Dim projectCurve1 As Features.ProjectCurve = CType(workPart.Features.FindObject("CPROJ(31)"), Features.ProjectCurve)

theSession.UpdateManager.SetUpdateFailureAction(projectCurve1, Update.FailureOption.AcceptAll)

Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

theSession.Preferences.Modeling.UpdatePending = False

' ----------------------------------------------
' Menu: Tools->Journal->Stop Recording
' ----------------------------------------------

End Sub
End Module

Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures

NX9, Win 7 Pro SP1
 
Replies continue below

Recommended for you

Is "COUNTERBORED SCREW HOLE" a custom name that you have given to the hole feature? If not, a good start would be to give the feature of interest a custom name. This way, your code can search for the feature type with the given name; if it is found in the file, we know we have the correct feature.

Your code also depends on "Extrude (3)" and "Cproj (31)"; if these features change in the new part, the code may crash.

www.nxjournaling.com
 
I can give it a name... That sounds like a more flexible method.

If you can show me how to do it, the name is now = "Thru Hole Top"

The dependency on Extrude(3) & Cproj(31) will always remain in place for this seed file.

Thanks

Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures

NX9, Win 7 Pro SP1
 
To rename a feature, right click on it in the part navigator and choose "rename"; type in a name of your choosing. Depending on your settings, the custom name may replace or be appended to the system generated name (assuming you use the name "test", the feature name may look like 'Hole (1)"test"' or 'test (1)').

The code below looks for a hole feature named "test", change the value of [tt]holeFeatureName[/tt] to the name that you choose to use.

Code:
Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim workPart As Part = theSession.Parts.Work

    Sub Main()

        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "C'Bore to C'Sink"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        'find counterbored screw hole feature with the specified name
        Const holeFeatureName As String = "test"
        Dim theHoleFeat As Features.HolePackage
        Dim found As Boolean = False
        For Each temp As Features.Feature In workPart.Features
            If temp.Name = holeFeatureName AndAlso temp.FeatureType = "HOLE PACKAGE" Then
                found = True
                theHoleFeat = temp
                Exit For
            End If
        Next

        If Not found Then
            lw.WriteLine("hole feature named '" & holeFeatureName & "' not found")
            Return
        End If

        ChangeHoleToCSink(theHoleFeat)

        Try
            Dim projectCurve1 As Features.ProjectCurve = CType(workPart.Features.FindObject("CPROJ(31)"), Features.ProjectCurve)

            theSession.UpdateManager.SetUpdateFailureAction(projectCurve1, Update.FailureOption.AcceptAll)

            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

            theSession.Preferences.Modeling.UpdatePending = False

        Catch ex As NXException

        End Try


        lw.Close()

    End Sub

    Sub ChangeHoleToCSink(ByVal theHole As Features.HolePackage)

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "change to csink")

        Try
            ' Invalid feature.
            theHole.SetGroupActive(True)
        Catch ex As NXException
            ex.AssertErrorCode(670060)
        End Try

        If Not workPart.Preferences.Modeling.GetHistoryMode Then
            Throw (New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
        End If

        Dim holePackageBuilder1 As Features.HolePackageBuilder
        holePackageBuilder1 = workPart.Features.CreateHolePackageBuilder(theHole)

        With holePackageBuilder1
            .HolePosition.PrepareMappingData()
            .ScrewClearanceHoleForm = Features.HolePackageBuilder.HoleForms.Countersink
            .ScrewClearanceCountersinkDiameter.RightHandSide = "0.507"
            .ScrewClearanceReliefDepth.RightHandSide = "0.06"
            .ScrewType = "Machine (82 degree)"
            .StartHoleData.ScrewType = "Socket Head, 4762"
            .StartHoleData.ScrewSize = "M1.6"
            .StartHoleData.FitOption = "Close (H12)"
            .MiddleHoleData.FitOption = "Close (H12)"
            .EndHoleData.FitOption = "Close (H12)"

        End With

        Dim nXObject1 As NXObject
        nXObject1 = holePackageBuilder1.Commit()

        holePackageBuilder1.HolePosition.CleanMappingData()

        holePackageBuilder1.Destroy()

        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.DoUpdate(markId1)

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module

www.nxjournaling.com
 
This works perfectly... Thanks Cowski!

Dave
Automotive Tooling / Aircraft Tooling / Ground Support Structures

NX9, Win 7 Pro SP1
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor