niedzviedz
Mechanical
- Apr 1, 2012
- 307
Hello everyone,
Some time ago I have created journal to report broken links. Link Because this thread is closed, I start this one. Now I would to add broken link to list, sort them and display. Below is my code:
I receive several errors:
* Line 76 - lw.writeline("Part Name:" & Plist.Part_name) -> Reference to a non-shared member requires an object reference
* Line 77 - lw.writeline("Name: {0},{1},{2}" PList.Part_Name, PList.Link_Name, PList.Parent_Name) -> Too many arguments in element "Public sub writeline(msg as string)" I used this page for example: Link
* Line 105 - if not Partlist.contains(child.name, theFeature.GetFeatureName,Parentname) then -> Can't convert value type string to PList
* Line 105 -> Too many arguments.
Any suggestions how to solve it?
With best regards
Michael
Some time ago I have created journal to report broken links. Link Because this thread is closed, I start this one. Now I would to add broken link to list, sort them and display. Below is my code:
Code:
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
Public class PList
'Implements IEquatable(Of PList)
Public Property Part_Name As String
Public Property Link_Name As String
Public Property Parent_Name As String
Public Sub New()
End Sub
Public Sub New(ByVal PartN As String,
ByVal LinkN As String,
ByVal ParentN As String)
Part_Name = PartN
Link_Name = LinkN
Parent_Name = ParentN
End Sub
End Class
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
Dim PartList as New list (of PList) ()
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
Partlist.sort
for each Czesc as PList in Partlist
lw.writeline("Part Name:" & Plist.Part_name)
lw.writeline("Name: {0},{1},{2}" PList.Part_Name, PList.Link_Name, PList.Parent_Name)
next
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
Dim MyPart As Part = child.Prototype.OwningPart
Dim sourceTag As string
Dim Parentname 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, Parentname, sourceTag)
if not Partlist.contains(child.name, theFeature.GetFeatureName,Parentname)
then
Partlist.add(new PList(child.name, theFeature.GetFeatureName,Parentname))
end if
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
msgbox(theloadstatus.getstatus(i))
If theLoadStatus.GetStatus(i) = 641058 Then
'read-only warning, file loaded ok
Else
'641044: file not found
lw.WriteLine("Nie znaleziono pliku")
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
if ex2.message = "File not found" then
lw.WriteLine("Błąd: " & partname & " " & "Nie znaleziono pliku")
else
lw.WriteLine("Błąd: " & partname & " " & ex2.Message)
end if
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
I receive several errors:
* Line 76 - lw.writeline("Part Name:" & Plist.Part_name) -> Reference to a non-shared member requires an object reference
* Line 77 - lw.writeline("Name: {0},{1},{2}" PList.Part_Name, PList.Link_Name, PList.Parent_Name) -> Too many arguments in element "Public sub writeline(msg as string)" I used this page for example: Link
* Line 105 - if not Partlist.contains(child.name, theFeature.GetFeatureName,Parentname) then -> Can't convert value type string to PList
* Line 105 -> Too many arguments.
Any suggestions how to solve it?
With best regards
Michael