Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

NX Journal - List of T problem

Status
Not open for further replies.

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:
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
 
Replies continue below

Recommended for you

* Line 76 - lw.writeline("Part Name:" & Plist.Part_name) -> Reference to a non-shared member requires an object reference
Code:
for each Czesc as PList in Partlist
	lw.writeline("Part Name:" & [s]Plist[/s]Czesc.Part_name)
	lw.writeline("Name: {0},{1},{2}" [s]PList[/s]Czesc.Part_Name, [s]PList[/s]Czesc.Link_Name, [s]PList[/s]Czesc.Parent_Name) 
next


* 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)"
Code:
lw.writeline("Name: " & PList.Part_Name & ", " & PList.Link_Name & ", " & PList.Parent_Name)

The NX listingWindow's .WriteLine method does not support string substitution like the console's.

* Line 105 - if not Partlist.contains(child.name, theFeature.GetFeatureName,Parentname) then -> Can't convert value type string to PList

The Partlist object contains Plist objects, not strings. The following link shows one way to find an object with a particular property value in a list:

* Line 105 -> Too many arguments.

This error is related to the one above.

www.nxjournaling.com
 
Thanks Cowski,

I fixed the code, so the errors doesn't show. Now I have two problems:
First, sort doesn't work. I thing because there is more elements in one line
Second, my exception from adding to list is broken, so even if element is on list, it add another one.

Code:
		if not partlist.contains(New PList() with { _
		        .Part_Name = child.name, _
			.Link_Name = theFeature.GetFeatureName }) then
		              Partlist.add(new PList(child.name, theFeature.GetFeatureName,Parentname))	

		end if

I have to figure out something else.



With best regards
Michael
 
The sort function does not work because the computer doesn't know how you want your custom objects sorted; you will need to write some code to tell it how to sort your objects.

There are multiple ways to solve the 2nd problem. One easy way would be to maintain a separate list of the components that you have processed so far. This could be a string list that holds the component name (or perhaps the component file path would serve better); as you process the assembly components, you can check this list and easily skip the ones already processed.

www.nxjournaling.com
 
Thank again Cowski.

I found this page about sort elements in list, and used it. Link
Below is my final code, maybe it will be useful for someone else.
Code:
Option Strict Off

Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic

Public class PList

	Public Property Part_Name As String
	Public Property Link_Name As String
	Public Property Parent_Name As String

	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) ()
    Dim List1 as New List (of String) 	
	
     Sub Main()

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

	if not IsNothing(c.RootComponent) then

            ReportComponentChildren(c.RootComponent, 0)
            ReportComponentChildren1(c.RootComponent, 0)
        else

            lw.WriteLine("Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try
    
    
	if Not IsNothing(Partlist) AndAlso Partlist.Count > 0 Then
		
		'Partlist.sort(Function(x, y) x.part_name.CompareTo(y.Part_name))

		partlist.sort(AddressOf Comparer)

		lw.writeline(" ")
		lw.writeline("Parts with broken links:")
		lw.writeline(" ")
		lw.writeline("---------------------------------------")
		lw.writeline("| Part name | Link name | Parent name |")
		lw.writeline("---------------------------------------")
		lw.writeline(" ")

		for each Czesc as PList in Partlist


			lw.writeline(czesc.Part_Name & "| " & czesc.Link_Name & "| " & czesc.Parent_Name) 

		next		
	end if

    lw.Close
 
    End Sub
 '******************************************************************************************************************
    Sub reportComponentChildren( ByVal comp As Component, ByVal indent As Integer)
    		Dim workPart As Part = theSession.Parts.Work
    		Dim dispPart As Part = theSession.Parts.Display

        For Each child As Component In comp.GetChildren()
	Dim MyPart As Part = child.Prototype.OwningPart

	Try

		if child.IsSuppressed = true then

			lw.writeline("Error: " & child.DisplayName & ".prt" & "   " & "Part is suppressed")
			Continue for
		end if
			Catch e1 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

		end try



        If LoadComponent(child) Then

		    		        

            Else

                'component could not be loaded

            End If

            reportComponentChildren(child, indent+1)
       
     
        Next
    End Sub
'**********************************************************
    Sub reportComponentChildren1( ByVal comp As Component, _
        ByVal indent As Integer)
	
        For Each child As Component In comp.GetChildren()

	Dim MyPart As Part = child.Prototype.OwningPart

	Try

		if child.IsSuppressed = true then

			'lw.writeline("Error: " & child.DisplayName & ".prt" & "   " & "Part is suppressed")
			Continue for
		end if
			Catch e11 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e11.ToString)

	end try
	    If LoadComponent(child) Then


	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)

				'lw.writeline(child.name) 
	
				if not list1.contains(child.name) then 
				
					list1.add(child.name)
					Partlist.add(new PList(child.name, theFeature.GetFeatureName,Parentname))	

				end if

		end if
           End If		

        Next
   
            Else
                'component could not be loaded
            End If 		

            reportComponentChildren1(child, indent + 1)
        Next
    End Sub

'*****************************************************************************************************************
Private Function Comparer(ByVal x As Plist, ByVal y As Plist) As Integer
	Dim result As Integer = x.Part_name.CompareTo(y.Part_name)

	If result = 0 Then

		result = x.Link_name.CompareTo(y.Link_name)
	End If

	Return result

End Function
'*****************************************************************************************************************
 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("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
		if ex2.message = "File not found" then 
	                lw.WriteLine("Error: " & partname & "   " & "File not found")		
		else
	                lw.WriteLine("Error: " & 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

With best regards
Michael
 
Hello,

I have made changes in journal - export XT. I added list of components which was already processed. I found out, if component is used more than once, then it's not processed. I tried changing code, but with no results. Any help will be welcome.
Here is my code:
Code:
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    Dim filename as string	
    Dim poz as string
    Dim Parentdir as String
    Dim TimeNote As string
    Dim list as New List (of string)
    Dim list2 as New List (of string)	

    Sub Main()

    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    TimeNote = System.DateTime.Now.Tostring("yyyy.MM.dd")

    lw.Open()

    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

	    ReportComponentChildren(c.RootComponent, 0)
            ReportComponentChildren2(c.RootComponent, 0)
        else

            lw.WriteLine(workpart.leaf & ".prt ->" & " Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try



	If Not IsNothing(lista) AndAlso list.Count > 0 Then

	lw.writeline(" ")
	lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline("POSITION IS NOT SET:") 
        lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline(" ")
	    	
	lista.sort
		for each alista as string in lista
			lw.writeline(alista)
		next

        End If

	If Not IsNothing(lista2) AndAlso list2.Count > 0 Then

	lw.writeline(" ")
	lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline("EXPORTED PARTS:") 
        lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline(" ")
	    	
	lista2.sort
		for each alista2 as string in lista2
			lw.writeline(alista2)
		next

        End If

    lw.Close
 
    End Sub

 '**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, ByVal indent As Integer)
    		Dim workPart As Part = theSession.Parts.Work
    		Dim dispPart As Part = theSession.Parts.Display

        For Each child As Component In comp.GetChildren()
	Dim MyPart As Part = child.Prototype.OwningPart

	Try

		if child.IsSuppressed = true then

			lw.writeline("Błąd: " & child.DisplayName & ".prt" & "   " & "Part is suppressed")
			Continue for
		end if
			Catch e1 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

		end try



        If LoadComponent(child) Then

		    		        

            Else

                'component could not be loaded

            End If

            reportComponentChildren(child, indent+1)
       
     
        Next
    End Sub

'**********************************************************
    Sub reportComponentChildren2( ByVal comp As Component, _
        ByVal indent As Integer)

	Dim dispPart As Part = theSession.Parts.Display
	Dim lw As ListingWindow = theSession.ListingWindow

	Dim tagList() As NXOpen.Tag
	Dim exportFileName As String = Nothing
	Dim exportFileName1 As String = Nothing
	Dim nazwa as string
	Dim path As String 
	Dim PSversion as integer = 240
	Dim layerNumber as Integer = 1	
	Dim i As Integer = 0
	Dim theBodies As New List(Of Body) 
	Dim inx As Integer = 0
	Dim theBodyTags as New List(Of Tag)


        For Each child As Component In comp.GetChildren()

		theBodyTags.clear()

		Try

		if child.IsSuppressed = true then

			Continue for
		end if
			Catch e1 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

		end try


             If LoadComponent(child) Then

		Dim MyPart As Part = child.Prototype.OwningPart 

	        filename = child.DisplayName()
	
		try
			poz = child.GetStringAttribute("poz")

				if poz = "" then 		
					if not list.contains(child.name) then 	

						list.add(child.name)	
	
					end if		
				end if


                	Catch ex21 As NXException
                    		If ex21.ErrorCode = 512008 Then

					if not lista.contains(child.name) then 	

						lista.add(child.name)	

					end if  	

					myPart.SetUserAttribute("Poz", -1, "", update.option.now)
				Else

		                        lw.WriteLine("error: " & ex21.ErrorCode & ", " & ex21.Message)
				end if 
		end try


			'MsgBox("Number of characters is: " & TextLength)

        	If isNumeric(poz) Then  

			if (poz > "000") and (poz < "351") then 
	
				theBodyTags.clear()

				  if not list2.contains(child.name) then

					list2.add(child.name)	
						For each tempBody as Body in mypart.Bodies

				 	  		if tempBody.Layer = 1 then

				 	   		   theBodytags.Add(tempBody.tag)
			
							end if
						Next 

						if theBodyTags.Count = 0 then
							'lw.writeline(Mypart.leaf & ".prt -> No bodies to export")
	    						'exit sub
							'return 
						end if	
				'end if					
			
			end if 

       
		exportFileName = myPart.FullPath
        	nazwa = myPart.Leaf

		parentDir = System.IO.Directory.GetParent(exportFileName).FullName
		parentDir = System.IO.Directory.GetParent(Parentdir).FullName
      
		'path = IO.Path.Combine(IO.Path.GetDirectoryName(myPart.FullPath), "step")
		path = parentdir + "\Parasolid"

		If(Not System.IO.Directory.Exists(Path)) Then

    			System.IO.Directory.CreateDirectory(Path)

		End If


		exportFileName = IO.Path.Combine(path, nazwa & ".x_t") 
	

	  	     'if this file already exists, delete it

       		If My.Computer.FileSystem.FileExists(exportFileName) Then

	           My.Computer.FileSystem.DeleteFile(exportFileName)

	        End If
 
       Dim numUnexported As Integer
	
       Try

       ufs.Ps.ExportLinkedData(theBodyTags.ToArray, theBodyTags.Count, exportFileName, PSversion, Nothing, numUnexported, Nothing) 

       Catch ex As NXException
           lw.WriteLine("*** ERROR ***")
           lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
       End Try
 
      	 		
		end if 
  	 end if

            Else

                'component could not be loaded

            End If

            reportComponentChildren2(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("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
		if ex2.message = "File not found" then 
	                lw.WriteLine("Błąd: " & partname & "   " & "File not found")		
		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


With best regards
Michael
 
Hello Cowski, I translate my code to english, that's why there was some errors in names of lists.
Here is code without errors:
Code:
Option Strict Off
 
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies
Imports System.Collections.Generic
 
Module NXJournal
 
    Public theSession As Session = Session.GetSession()
    Public ufs As UFSession = UFSession.GetUFSession()
    Public lw As ListingWindow = theSession.ListingWindow
    Dim filename as string	
    Dim poz as string
    Dim Parentdir as String
    Dim TimeNote As string
    Dim list as New List (of string)
    Dim list2 as New List (of string)	

    Sub Main()

    Dim workPart As Part = theSession.Parts.Work
    Dim dispPart As Part = theSession.Parts.Display
 
    TimeNote = System.DateTime.Now.Tostring("yyyy.MM.dd")

    lw.Open()

    Try
        Dim c As ComponentAssembly = dispPart.ComponentAssembly

	if not IsNothing(c.RootComponent) then

	    ReportComponentChildren(c.RootComponent, 0)
            ReportComponentChildren2(c.RootComponent, 0)
        else

            lw.WriteLine(workpart.leaf & ".prt ->" & " Part has no components")

        end if
    Catch e As Exception
        theSession.ListingWindow.WriteLine("Failed: " & e.ToString)
    End Try



	If Not IsNothing(list) AndAlso list.Count > 0 Then

	lw.writeline(" ")
	lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline("POSITION IS NOT SET:") 
        lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline(" ")
	    	
	list.sort
		for each alist as string in list
			lw.writeline(alist)
		next

        End If

	If Not IsNothing(list2) AndAlso list2.Count > 0 Then

	lw.writeline(" ")
	lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline("EXPORTED PARTS:") 
        lw.writeline("----------------------------------------------------------------------------------------------- ")
	lw.writeline(" ")
	    	
	list2.sort
		for each alist2 as string in list2
			lw.writeline(alist2)
		next

        End If

    lw.Close
 
    End Sub

 '**********************************************************
    Sub reportComponentChildren( ByVal comp As Component, ByVal indent As Integer)
    		Dim workPart As Part = theSession.Parts.Work
    		Dim dispPart As Part = theSession.Parts.Display

        For Each child As Component In comp.GetChildren()
	Dim MyPart As Part = child.Prototype.OwningPart

	Try

		if child.IsSuppressed = true then

			lw.writeline("Błąd: " & child.DisplayName & ".prt" & "   " & "Part is suppressed")
			Continue for
		end if
			Catch e1 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

		end try



        If LoadComponent(child) Then

		    		        

            Else

                'component could not be loaded

            End If

            reportComponentChildren(child, indent+1)
       
     
        Next
    End Sub

'**********************************************************
    Sub reportComponentChildren2( ByVal comp As Component, _
        ByVal indent As Integer)

	Dim dispPart As Part = theSession.Parts.Display
	Dim lw As ListingWindow = theSession.ListingWindow

	Dim tagList() As NXOpen.Tag
	Dim exportFileName As String = Nothing
	Dim exportFileName1 As String = Nothing
	Dim nazwa as string
	Dim path As String 
	Dim PSversion as integer = 240
	Dim layerNumber as Integer = 1	
	Dim i As Integer = 0
	Dim theBodies As New List(Of Body) 
	Dim inx As Integer = 0
	Dim theBodyTags as New List(Of Tag)


        For Each child As Component In comp.GetChildren()

		theBodyTags.clear()

		Try

		if child.IsSuppressed = true then

			Continue for
		end if
			Catch e1 As Exception
		        theSession.ListingWindow.WriteLine("Failed: " & e1.ToString)

		end try


             If LoadComponent(child) Then

		Dim MyPart As Part = child.Prototype.OwningPart 

	        filename = child.DisplayName()
	
		try
			poz = child.GetStringAttribute("poz")

				if poz = "" then 		
					if not list.contains(child.name) then 	

						list.add(child.name)	
	
					end if		
				end if


                	Catch ex21 As NXException
                    		If ex21.ErrorCode = 512008 Then

					if not list.contains(child.name) then 	

						list.add(child.name)	

					end if  	

					myPart.SetUserAttribute("Poz", -1, "", update.option.now)
				Else

		                        lw.WriteLine("error: " & ex21.ErrorCode & ", " & ex21.Message)
				end if 
		end try


			'MsgBox("Number of characters is: " & TextLength)

        	If isNumeric(poz) Then  

			if (poz > "000") and (poz < "351") then 
	
				theBodyTags.clear()

				  if not list2.contains(child.name) then

					list2.add(child.name)	
						For each tempBody as Body in mypart.Bodies

				 	  		if tempBody.Layer = 1 then

				 	   		   theBodytags.Add(tempBody.tag)
			
							end if
						Next 

						if theBodyTags.Count = 0 then
							'lw.writeline(Mypart.leaf & ".prt -> No bodies to export")
	    						'exit sub
							'return 
						end if	
				'end if					
			
			end if 

       
		exportFileName = myPart.FullPath
        	nazwa = myPart.Leaf

		parentDir = System.IO.Directory.GetParent(exportFileName).FullName
		parentDir = System.IO.Directory.GetParent(Parentdir).FullName
      
		'path = IO.Path.Combine(IO.Path.GetDirectoryName(myPart.FullPath), "step")
		path = parentdir + "\Parasolid"

		If(Not System.IO.Directory.Exists(Path)) Then

    			System.IO.Directory.CreateDirectory(Path)

		End If


		exportFileName = IO.Path.Combine(path, nazwa & ".x_t") 
	

	  	     'if this file already exists, delete it

       		If My.Computer.FileSystem.FileExists(exportFileName) Then

	           My.Computer.FileSystem.DeleteFile(exportFileName)

	        End If
 
       Dim numUnexported As Integer
	
       Try

       ufs.Ps.ExportLinkedData(theBodyTags.ToArray, theBodyTags.Count, exportFileName, PSversion, Nothing, numUnexported, Nothing) 

       Catch ex As NXException
           lw.WriteLine("*** ERROR ***")
           lw.WriteLine(ex.ErrorCode.ToString & " : " & ex.Message)
       End Try
 
      	 		
		end if 
  	 end if

            Else

                'component could not be loaded

            End If

            reportComponentChildren2(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("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
		if ex2.message = "File not found" then 
	                lw.WriteLine("Błąd: " & partname & "   " & "File not found")		
		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

With best regards
Michael
 
The problem is here:
Code:
        	If isNumeric(poz) Then  

			if (poz > "000") and (poz < "351") then 
	
				theBodyTags.clear()

				  if not list2.contains(child.name) then

					list2.add(child.name)	
						For each tempBody as Body in mypart.Bodies

				 	  		if tempBody.Layer = 1 then

				 	   		   theBodytags.Add(tempBody.tag)
			
							end if
						Next 

						if theBodyTags.Count = 0 then
							'lw.writeline(Mypart.leaf & ".prt -> No bodies to export")
	    						'exit sub
							'return 
						end if	
				'end if					
			
			end if

If I remove those two lines:
Code:
  if not list2.contains(child.name) then
     list2.add(child.name)
It's working good.


With best regards
Michael
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor