Journal to display broken links
Journal to display broken links
(OP)
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.
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:
But I gets error.
Any one can help me solve what I did wrong?
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





RE: Journal to display broken links
CODE
For Each theFeature As Features.Feature In dispPart.Featureswww.nxjournaling.com
RE: Journal to display broken links
With best regards
Michael
RE: Journal to display broken links
www.nxjournaling.com
RE: Journal to display broken links
CODE
With best regards
Michael
RE: Journal to display broken links
www.nxjournaling.com
RE: Journal to display broken links
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 ModuleI 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
RE: Journal to display broken links
UF_WAVE_ask_broken_link_source_part
UF_WAVE_ask_link_source
www.nxjournaling.com
RE: Journal to display broken links
With best regards
Michael
RE: Journal to display broken links
Thanks Cowski and niedzviedz for your support.
I really appreciate help.
I installed macro. In my opinion works good.
Good job
Best regards
Mafi
RE: Journal to display broken links
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:
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 ModuleAnyone can help me solve my problem?
With best regards
Michael
RE: Journal to display broken links
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 ModuleCode 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
RE: Journal to display broken links
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 Trywww.nxjournaling.com
RE: Journal to display broken links
Have you integrated cowski suggests into your code. I'd like to see your final code if you could please post it.
Thank you.
RE: Journal to display broken links
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 ModuleIn 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
- 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
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
RE: Journal to display broken links
www.nxjournaling.com
RE: Journal to display broken links
What do you mean by saving it to a data structure?
Thanks.
RE: Journal to display broken links
www.nxjournaling.com