Cancel
Showing results for 
Search instead for 
Did you mean: 

Editing an existing journal

Phenom
Phenom

I keep saying this, and I need to actually find some time to learn...  this sample journal was provided by GTAC, to break wave links, but it only works on bodies.  I'd like to make it work on any wave linked geometry.  I see the line with "Linked body", would additional lines, or a different line do it?

 

Option Strict Off  

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module break_all_wave_linked_bodies

    Dim theSession As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim dispPart As Part = theSession.Parts.Display
        Dim thisFeat As NXObject
        Dim is_broken As Boolean

        Dim myFeats As Features.FeatureCollection = dispPart.Features

        Dim featureName As String

        lw.Open()

        For Each thisFeat In myFeats

            ufs.Modl.AskFeatSysname(thisFeat.Tag, featureName)
            lw.WriteLine("Feature: " & featureName)
            If featureName.Compare(featureName, 0, "Linked Body", 0, 11, True) = 0 Then
                lw.WriteLine("Breaking link...")
                ufs.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                ufs.Modl.Update()
                ufs.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine("is_broken??? " & is_broken.ToString)
            End If
            ufs.Modl.Update()
        Next

    End Sub

  Public Function GetUnloadOption(ByVal dummy As String) As Integer

      Return Session.LibraryUnloadOption.Immediately

  End Function

End Module
-Dave
NX 11 | Teamcenter 11 | Windows 8.1
11 REPLIES

Re: Editing an existing journal

It looks like the program works for any feature, and is only checking the feature name to identify wave links. It looks like the program is checking if the first 11 characters of the feature name matches "Linked Body". If you want every feature whose name starts with "Linked", check the first 6 characters for that instead. 

            If featureName.Compare(featureName, 0, "Linked Body", 0, 11, True) = 0 Then

becomes

            If featureName.Compare(featureName, 0, "Linked", 0, 6, True) = 0 Then

I am not a real vb programmer, so test this first ;*)

 

Reference: https://msdn.microsoft.com/en-us/library/1e058ek8(v=vs.110).aspx

Mark Rief
Retired Siemens

Re: Editing an existing journal

Phenom
Phenom

I'll give it a try, thanks.

-Dave
NX 11 | Teamcenter 11 | Windows 8.1

Re: Editing an existing journal

Honored Contributor
Honored Contributor

GTAC has a sample that will check to see if a feature is linked to another part (nx_api5410). You should be able to use this in conjunction with the .SetLinkData method to break any wave link in the file. Also, see nx_api5409 for a fully functioning journal that makes use of the subroutine.

Re: Editing an existing journal

Honored Contributor
Honored Contributor

Here's a quick journal based on my last post. The code has not been thoroughly tested...

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "break all wave links")

        lw.Open()

        Dim is_broken As Boolean = False

        For Each thisFeat As Features.Feature In theSession.Parts.Display.Features
            lw.WriteLine("Feature: " & thisFeat.GetFeatureName)
            If IsLinkedFeature(thisFeat) Then
                lw.WriteLine(" Breaking link...")
                theUfSession.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                theUfSession.Modl.Update()
                theUfSession.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine(" is_broken? " & is_broken.ToString)
            End If
            theUfSession.Modl.Update()
        Next

        lw.Close()

    End Sub

    Function IsLinkedFeature(theFeature As Features.Feature) As Boolean
        ' There is no NXOpen method available which can be used to determine if a feature
        ' is linked to another part, so this function demonstrates calling a Check-mate
        ' function to get that information.  See ER 6669518.

        Dim arule As String = "mqc_isLinkedFeature(" & theFeature.Tag.ToString & ")"

        Dim ruleName As String = ""
        theUfSession.Cfi.GetUniqueFilename(ruleName)

        theSession.Parts.Work.RuleManager.CreateDynamicRule("root:", ruleName, "Boolean", arule, "")
        Dim isLinked As String
        isLinked = theSession.Parts.Work.RuleManager.EvaluateAsString("root:" & ruleName & ":")
        theSession.Parts.Work.RuleManager.DeleteDynamicRule("root:", ruleName)

        If isLinked.CompareTo("TRUE") = 0 Then Return True Else Return False

    End Function

    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

Re: Editing an existing journal

Phenom
Phenom

@cowski1  I created a test file with a linked face, body, mirror body, curve, and a point.  Your journal broke the link on the face, and body.

-Dave
NX 11 | Teamcenter 11 | Windows 8.1

Re: Editing an existing journal

Phenom
Phenom

Using my blunt force an ignorance approach, I have started to edit the original journal.  So far I have it breaking the linked face, body, datum, and curve.  I have not found the right terms for the linked point, and mirror body.

 

Option Strict Off  

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.UI
Imports NXOpen.Utilities

Module break_all_wave_linked_bodies

    Dim theSession As Session = Session.GetSession()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim dispPart As Part = theSession.Parts.Display
        Dim thisFeat As NXObject
        Dim is_broken As Boolean

        Dim myFeats As Features.FeatureCollection = dispPart.Features

        Dim featureName As String

        lw.Open()

        For Each thisFeat In myFeats

            ufs.Modl.AskFeatSysname(thisFeat.Tag, featureName)
            lw.WriteLine("Feature: " & featureName)
            If featureName.Compare(featureName, 0, "Linked Body", 0, 11, True) = 0 Then
                lw.WriteLine("Breaking link...")
                ufs.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                ufs.Modl.Update()
                ufs.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine("is_broken??? " & is_broken.ToString)
			End If
			If featureName.Compare(featureName, 0, "Linked Face", 0, 11, True) = 0 Then
                lw.WriteLine("Breaking link...")
                ufs.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                ufs.Modl.Update()
                ufs.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine("is_broken??? " & is_broken.ToString)
            End If
			If featureName.Compare(featureName, 0, "Linked Composite Curve", 0, 11, True) = 0 Then
                lw.WriteLine("Breaking link...")
                ufs.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                ufs.Modl.Update()
                ufs.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine("is_broken??? " & is_broken.ToString)
            End If
			If featureName.Compare(featureName, 0, "Linked Datum", 0, 11, True) = 0 Then
                lw.WriteLine("Breaking link...")
                ufs.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                ufs.Modl.Update()
                ufs.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine("is_broken??? " & is_broken.ToString)
            End If
            ufs.Modl.Update()
        Next

    End Sub

  Public Function GetUnloadOption(ByVal dummy As String) As Integer

      Return Session.LibraryUnloadOption.Immediately

  End Function

End Module
-Dave
NX 11 | Teamcenter 11 | Windows 8.1

Re: Editing an existing journal

Honored Contributor
Honored Contributor

Ok then, try this one:

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF

Module Module1

    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()

    Dim theUI As UI = UI.GetUI()
    Dim lw As ListingWindow = theSession.ListingWindow

    Sub Main()

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "break all wave links")

        lw.Open()

        Dim is_broken As Boolean = False

        For Each thisFeat As Features.Feature In theSession.Parts.Display.Features
            lw.WriteLine("Feature: " & thisFeat.GetFeatureName)
            If IsLinkedFeature(thisFeat) Then

                lw.WriteLine(" Breaking link...")

                If TypeOf (thisFeat) Is Features.MirrorBody Then
                    'handle linked mirror body

                    'lw.WriteLine("linked mirror body found")
                    Dim mirrorBodyBuilder1 As Features.MirrorBodyBuilder
                    mirrorBodyBuilder1 = theSession.Parts.Work.Features.CreateMirrorBodyBuilder(thisFeat)
                    mirrorBodyBuilder1.Associative = False
                    Dim nullTaggedObject As TaggedObject = Nothing
                    mirrorBodyBuilder1.SourcePartOccurrence = nullTaggedObject

                    Dim nXObject1 As NXObject
                    nXObject1 = mirrorBodyBuilder1.Commit()

                    mirrorBodyBuilder1.Destroy()

                ElseIf TypeOf (thisFeat) Is Features.WavePoint Then
                    'handle linked point
                    Dim wavePointBuilder1 As Features.WavePointBuilder
                    wavePointBuilder1 = theSession.Parts.Work.Features.CreateWavePointBuilder(thisFeat)
                    wavePointBuilder1.Associative = False
                    Dim nullTaggedObject As TaggedObject = Nothing
                    wavePointBuilder1.SourcePartOccurrence = nullTaggedObject

                    Dim nXObject1 As NXObject
                    nXObject1 = wavePointBuilder1.Commit()

                    wavePointBuilder1.Destroy()

                ElseIf TypeOf (thisFeat) Is Features.ExtractFace Then
                    'handle linked region
                    Dim extractFaceBuilder1 As Features.ExtractFaceBuilder
                    extractFaceBuilder1 = theSession.Parts.Work.Features.CreateExtractFaceBuilder(thisFeat)
                    extractFaceBuilder1.Associative = False

                    Dim nXObject1 As NXObject
                    nXObject1 = extractFaceBuilder1.Commit()

                    extractFaceBuilder1.Destroy()

                Else
                    'handle the other linked stuff
                    theUfSession.Wave.SetLinkData(thisFeat.Tag, NXOpen.Tag.Null, NXOpen.Tag.Null, False)
                    theUfSession.Modl.Update()

                End If
                theUfSession.Wave.IsLinkBroken(thisFeat.Tag, is_broken)
                lw.WriteLine(" is_broken? " & is_broken.ToString)
            End If
            Dim nErrs1 As Integer
            nErrs1 = theSession.UpdateManager.DoUpdate(markId1)
            theSession.Preferences.Modeling.UpdatePending = False
        Next

        lw.Close()

    End Sub

    Function IsLinkedFeature(theFeature As Features.Feature) As Boolean
        ' There is no NXOpen method available which can be used to determine if a feature
        ' is linked to another part, so this function demonstrates calling a Check-mate
        ' function to get that information.  See ER 6669518.

        Dim arule As String = "mqc_isLinkedFeature(" & theFeature.Tag.ToString & ")"

        Dim ruleName As String = ""
        theUfSession.Cfi.GetUniqueFilename(ruleName)

        theSession.Parts.Work.RuleManager.CreateDynamicRule("root:", ruleName, "Boolean", arule, "")
        Dim isLinked As String
        isLinked = theSession.Parts.Work.RuleManager.EvaluateAsString("root:" & ruleName & ":")
        theSession.Parts.Work.RuleManager.DeleteDynamicRule("root:", ruleName)

        If isLinked.CompareTo("TRUE") = 0 Then Return True Else Return False

    End Function

    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

Re: Editing an existing journal

Phenom
Phenom

That broke everything!  cool, thanks.

-Dave
NX 11 | Teamcenter 11 | Windows 8.1

Re: Editing an existing journal

Honored Contributor
Honored Contributor

Wow, this is the first time I've been thanked for breaking everything!