Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Journal to display broken links 1

Status
Not open for further replies.

niedzviedz

Mechanical
Apr 1, 2012
307
Hello,
I wanna write some journal to process whole assembly and display only parts with broken links. Below is code which I mix with two codes.

Code:
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow

    Dim theUfSession As UFSession = UFSession.GetUFSession
    Dim sourceTag As Tag
    Dim linkBroken As Boolean = True
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    Sub Main()

    lw.Open
    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

            ReportComponentChildren(c.RootComponent, 0)
        else

            lw.WriteLine("Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    lw.Close
 
    End Sub
 
'**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, _
        ByVal indent As Integer)

	Dim dispPart As Part = theSession.Parts.Display
        Dim Length as Integer
	
        For Each child As Component In comp.GetChildren()

        For Each theFeature As Features.Feature In dispPart.Features
            If theFeature.FeatureType.Contains("LINKED") Then
               theUfSession.Wave.IsLinkBroken(theFeature.Tag, linkBroken)
                 If linkBroken Then
                    lw.WriteLine("link to parent geometry is broken")
		    lw.WriteLine("  " & theFeature.GetFeatureName)
		end if
            End If
        Next    		
            reportComponentChildren(child, indent + 1)
        Next
    End Sub


'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************

End Module
Unfortunately it doesn't work like I want, because it don't display broken links. Separately second code (the one to display broken links in part) works perfect.
I also would like to add feature to display parent, something like that:

Code:
lw.WriteLine("  " & theFeature.GetParents)
But I gets error.

Any one can help me solve what I did wrong?






With best regards
Michael
 
Replies continue below

Recommended for you

Are you only interested in the features of the displayed part?

Code:
For Each theFeature As Features.Feature In [highlight #FCE94F]dispPart.Features[/highlight]

www.nxjournaling.com
 
No, I would like to proced whole assembly and find parts with broken links.

With best regards
Michael
 
Changing this line to:
Code:
For Each theFeature As Features.Feature In workPart.Features
Also doesn't solved the problem. What I have put in highlighted place?

With best regards
Michael
 
Thanks Cowski,

After some fight and reading similar threads I figured it out. Below is working code:

Code:
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow

    Dim theUfSession As UFSession = UFSession.GetUFSession
    Dim sourceTag As Tag
    Dim linkBroken As Boolean = True
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    Sub Main()

    lw.Open
    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

            ReportComponentChildren(c.RootComponent, 0)
        else

            lw.WriteLine("Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    lw.Close
 
    End Sub
 
'**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, _
        ByVal indent As Integer)

        For Each child As Component In comp.GetChildren()

		lw.WriteLine("file name: " & child.name)

	Dim MyPart As Part = child.Prototype.OwningPart

	   For Each theFeature as Features.Feature In MyPart.Features
            If theFeature.FeatureType.Contains("LINKED") Then
               theUfSession.Wave.IsLinkBroken(theFeature.Tag, linkBroken)
                If linkBroken Then
                    'lw.WriteLine("link to parent geometry is broken")
		    'lw.WriteLine("file name: " & child.name)
		    lw.WriteLine("  " & theFeature.GetFeatureName)
		end if
           End If		
        Next    		
            reportComponentChildren(child, indent + 1)
        Next
    End Sub


'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************

End Module

I have one more questions, is there any chance to obtain parent of broken link? In documentation I found this .GetParents, but it doesn't work.

Code:
lw.WriteLine("  " & theFeature.GetParents)



With best regards
Michael
 
Thanks Cowski, I will try to investigate this functions.

With best regards
Michael
 
Hello guys,

Thanks Cowski and niedzviedz for your support.
I really appreciate help.

I installed macro. In my opinion works good.

Good job ;-)

Best regards
Mafi

 
Hello everyone,
I tried include function to display parent of broken link. Below is code, which only work on part and on non broken link. When link is broken I get message "could not fully load parent file....". When I comment lines:

If sourceTag = Tag.Null Then
lw.WriteLine("could not fully load parent file...")

then I get error: "System.NullReferenceException: Object reference not set to an instance of an object in Module1.Main() c:\(...)\journal.vb:line 40"

Here is my code:

Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
 
Module Module1
 
    Sub Main()
 
        Dim theSession As Session = Session.GetSession()
        Dim theUfSession As UFSession = UFSession.GetUFSession
	Dim sourceTag As Tag
 
        If IsNothing(theSession.Parts.Work) Then
            'active part required
            Return
        End If
 
        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()
 
        For Each theFeature As Features.Feature In workPart.Features
            If theFeature.FeatureType.Contains("LINKED") Then
                lw.WriteLine("Linked feature found:")
                lw.WriteLine("  " & theFeature.GetFeatureName)
                lw.WriteLine("")
		theUfSession.Wave.AskLinkSource(theFeature.Tag, True, sourceTag)

		If sourceTag = Tag.Null Then
                        lw.WriteLine("could not fully load parent file...")

		else 
			Dim myTaggedObj As TaggedObject
                        Dim source As body
                        Dim sourceFile As Part

			myTaggedObj = theSession.GetObjectManager.GetTaggedObject(sourceTag)
                        source = myTaggedObj
                        sourceFile = source.OwningPart
                        lw.WriteLine("parent file: " & sourceFile.FullPath)


                end if

            End If
        Next
 
        lw.Close()
 
    End Sub
 
End Module

Anyone can help me solve my problem?


With best regards
Michael
 
Hello again. I figured out how to displays parents of broken links. Below is my code:

Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow

    Dim theUfSession As UFSession = UFSession.GetUFSession
    Dim sourceTag As Tag
    Dim linkBroken As Boolean = True
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    Sub Main()

    lw.Open
    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly
	if not IsNothing(c.RootComponent) then
            ReportComponentChildren(c.RootComponent, 0)
        else
            lw.WriteLine("Part has no components")
        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    lw.Close
 
    End Sub
 
'**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, _
        ByVal indent As Integer)

        For Each child As Component In comp.GetChildren()

		lw.WriteLine("file name: " & child.name)
'		lw.WriteLine("  ")

	Dim MyPart As Part = child.Prototype.OwningPart
	Dim sourceTag As string
	Dim Partname as string

	   For Each theFeature as Features.Feature In MyPart.Features
            If theFeature.FeatureType.Contains("LINKED") Then
               theUfSession.Wave.IsLinkBroken(theFeature.Tag, linkBroken)
			
                If linkBroken Then
			theUfSession.Wave.AskbrokenLinkSourcepart(theFeature.Tag, Partname, sourceTag)
'		lw.WriteLine("file name: " & child.name)
		lw.WriteLine("  " & theFeature.GetFeatureName)
		lw.WriteLine("		parent file: " & Partname)
		lw.WriteLine("  ")
		end if
           End If		
        Next    		
            reportComponentChildren(child, indent + 1)
        Next
    End Sub

'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************

End Module

Code works perfect except time when some parts in assembly are closed or suppressed, then I've got error. How can I exclude / ignore them from proceed?

With best regards
Michael
 
I have a function that attempts to load a component, it first checks to see if the component is already loaded. Below is a snippet that performs the check.

Code:
Dim thePart As Part = theComponent.Prototype.OwningPart

Try
    If thePart.IsFullyLoaded Then
        'component is fully loaded
    Else
        'component is partially loaded
    End If
Catch ex As NullReferenceException
    'component is not loaded
End Try

www.nxjournaling.com
 
@Niedzviedz,

Have you integrated cowski suggests into your code. I'd like to see your final code if you could please post it.

Thank you.
 
Hello everyone.

Thanks @Cowski for Your support. I have integrated Your code into mine. Now I don't receive error message.
Below is my final code:

Code:
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow

    Dim theUfSession As UFSession = UFSession.GetUFSession
    Dim sourceTag As Tag
    Dim linkBroken As Boolean = True
    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    Sub Main()

    lw.Open
    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

            ReportComponentChildren(c.RootComponent, 0)
        else

            lw.WriteLine("Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    lw.Close
 
    End Sub
 
'**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, _
        ByVal indent As Integer)
	
        For Each child As Component In comp.GetChildren()

	    If LoadComponent(child) Then

		lw.WriteLine("file name: " & child.name)
'		lw.WriteLine("  ")

	Dim MyPart As Part = child.Prototype.OwningPart
	Dim sourceTag As string
	Dim Partname as string

	   For Each theFeature as Features.Feature In MyPart.Features
            If theFeature.FeatureType.Contains("LINKED") Then
               theUfSession.Wave.IsLinkBroken(theFeature.Tag, linkBroken)
			
                If linkBroken Then
			theUfSession.Wave.AskbrokenLinkSourcepart(theFeature.Tag, Partname, sourceTag)

'		lw.WriteLine("file name: " & child.name)
		lw.WriteLine("  " & theFeature.GetFeatureName)
		lw.WriteLine("		parent file: " & Partname)
		lw.WriteLine("  ")

		end if
           End If		
        Next
               Else
                'component could not be loaded
            End If 		
            reportComponentChildren(child, indent + 1)
        Next
    End Sub

    Private Function LoadComponent(ByVal theComponent As Component) As Boolean
 
        Dim thePart As Part = theComponent.Prototype.OwningPart
 
        Dim partName As String = ""
        Dim refsetName As String = ""
        Dim instanceName As String = ""
        Dim origin(2) As Double
        Dim csysMatrix(8) As Double
        Dim transform(3, 3) As Double
 
        Try
            If thePart.IsFullyLoaded Then
                'component is fully loaded
            Else
                'component is partially loaded
            End If
            Return True
        Catch ex As NullReferenceException
            'component is not loaded
            Try
                ufs.Assem.AskComponentData(theComponent.Tag, partName, refsetName, instanceName, origin, csysMatrix, transform)
 
                Dim theLoadStatus As PartLoadStatus
                theSession.Parts.Open(partName, theLoadStatus)
 
                If theLoadStatus.NumberUnloadedParts > 0 Then
 
                    Dim allReadOnly As Boolean = True
                    For i As Integer = 0 To theLoadStatus.NumberUnloadedParts - 1
                        If theLoadStatus.GetStatus(i) = 641058 Then
                            'read-only warning, file loaded ok
                        Else
                            '641044: file not found
                            lw.WriteLine("file not found")
                            allReadOnly = False
                        End If
                    Next
                    If allReadOnly Then
                        Return True
                    Else
                        'warnings other than read-only...
                        Return False
                    End If
                Else
                    Return True
                End If
 
            Catch ex2 As NXException
                lw.WriteLine("error: " & ex2.Message)
                Return False
            End Try
        Catch ex As NXException
            'unexpected error
            lw.WriteLine("error: " & ex.Message)
            Return False
        End Try
    End Function

'**********************************************************
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        Return Session.LibraryUnloadOption.Immediately
    End Function
'**********************************************************

End Module

In this code I have line:

Code:
lw.WriteLine("file name: " & child.name)

in two places:
- One is uncommented and the second is commented, in this configuration journal writes all parts in assembly plus add broken links. Example:

Code:
file name: 004_PART_1
file name: 000_PART_2
  LINKED_FACE(14)
		parent file: C:\PARTS\003_PART_3.prt
  LINKED_FACE(15)
		parent file: C:\PARTS\003_PART_3.prt

- if I reverse it, so the first one is commented and the second is uncommented, journal only display parts with broken links.If there is more than one broken link in part, journal will write part name and broken link multiple times. Example:

Code:
file name: 000_PART_2
  LINKED_FACE(14)
		parent file: C:\PARTS\003_PART_3.prt
file name: 000_PART_2
  LINKED_FACE(15)
		parent file: C:\PARTS\003_PART_3.prt

I would like journal display only parts with broken links but in first style. Has someone any idea how to realize this?



With best regards
Michael
 
Rather than immediately displaying the broken link information, I'd suggest saving it to a data structure of your choosing. After all the parts have been examined, you can sort the information (if needed) and display it however you choose.

www.nxjournaling.com
 
You could save the information to a list, an array, a data table, etc, or some combination thereof. A small, custom class to contain and manage the information would be another option.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor