cancel
Showing results for 
Search instead for 
Did you mean: 

Reference and Arrangement listing within all components

Valued Contributor
Valued Contributor

Has anyone found a way or customized a Journal code to list out per component (assembly and part) all the reference sets and arrangements available, not just the ones in use?

 

So it may result in an output like this:

Component 163885 Path: 10461510-1/A1 Reference Sets: Model, ALR, Simple

Component 65051 Path: 10461549-1/A1 Reference Sets: Model

Component 65059 Path: 10461550-1/A1 Reference Sets: Model

Where each line shows the component and a list of the reference sets available within each component.

 

And that also would follow suit with arrangements as well…

Component 163885 Path: 10461510-1/A1 Arrangements: Open, Closed, Stowed

Component 65051 Path: 10461549-1/A1 Arrangements: Open

Component 65059 Path: 10461550-1/A1 Arrangements: Arrangement 1

 

This customized code exists (see below) for listing out the reference sets for the work part, but I would need to spend some learning time to figure out how to adapt it to pull this kind of info for every part and subassembly. I'm hoping folks may have something already done or at least more towards that result.

 

Thanks!

Option Strict Off
Imports System
Imports NXOpen

Module report_reference_sets_in_workpart


    Sub Main()

        Dim s As Session = Session.GetSession()
        Dim workpart As Part = s.Parts.Work
        Dim lw As ListingWindow = s.ListingWindow
        lw.Open()

        Dim refSets() As ReferenceSet = workpart.GetAllReferenceSets

        For Each refSet As ReferenceSet In refSets
            lw.WriteLine(" Reference Set: " + refSet.Name)
        Next

    End Sub


    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

    End Function

End Module
2 REPLIES

Re: Reference and Arrangement listing within all components

Phenom
Phenom

Try the following journal. The arrangement/ref set in use is marked with an asterisk *.

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Assemblies

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, "NXJ")

        lw.Open()

        lw.WriteLine("Assembly: " & theSession.Parts.Display.Leaf)

        Dim c As ComponentAssembly = theSession.Parts.Display.ComponentAssembly
        If Not IsNothing(c.RootComponent) Then

            '*** insert code to process 'root component' (assembly file)
            Dim theArrangements() As Arrangement = theSession.Parts.Display.ComponentAssembly.Arrangements.ToArray
            If theArrangements.Length = 0 Then
                lw.WriteLine("  no arrangements")
            Else
                lw.WriteLine("  Arrangements:")
            End If
            For Each tempArr As Arrangement In theArrangements
                If tempArr.Equals(c.RootComponent.UsedArrangement) Then
                    lw.WriteLine("    * " & tempArr.Name)
                Else
                    lw.WriteLine("    " & tempArr.Name)

                End If

            Next
            '*** end of code to process root component
            reportComponentChildren(c.RootComponent, 1)
        Else
            '*** insert code to process piece part
            'lw.WriteLine("Part has no components")
        End If


        lw.Close()

    End Sub

    Sub reportComponentChildren(ByVal comp As Component, ByVal indent As Integer)

        For Each child As Component In comp.GetChildren()
            '*** insert code to process component or subassembly
            lw.WriteLine(New String(" ", indent * 2) & child.DisplayName())

            Try
                If child.Prototype.OwningPart.IsFullyLoaded Then
                    'component is fully loaded
                Else
                    'component is partially loaded
                End If

                'report reference sets
                lw.WriteLine(New String(" ", indent * 2) & "  Reference sets:")
                For Each tempRefSet As ReferenceSet In child.Prototype.OwningPart.GetAllReferenceSets
                    If child.ReferenceSet = tempRefSet.Name Then
                        lw.WriteLine(New String(" ", indent * 2) & "    * " & tempRefSet.Name)
                    Else
                        lw.WriteLine(New String(" ", indent * 2) & "    " & tempRefSet.Name)
                    End If
                Next

            Catch ex As NullReferenceException
                'component is not loaded
                lw.WriteLine(New String(" ", indent * 2) & "  component not loaded")
            End Try

            '*** end of code to process component or subassembly
            If child.GetChildren.Length <> 0 Then
                '*** this is a subassembly, add code specific to subassemblies

                Dim theArrangements() As Arrangement = child.Prototype.OwningPart.ComponentAssembly.Arrangements.ToArray
                If theArrangements.Length = 0 Then
                    lw.WriteLine("no arrangements")
                Else
                    lw.WriteLine(New String(" ", indent * 2) & "  Arrangements:")
                End If
                For Each tempArr As Arrangement In theArrangements
                    If tempArr.Equals(child.UsedArrangement) Then
                        lw.WriteLine(New String(" ", indent * 2) & "    * " & tempArr.Name)
                    Else
                        lw.WriteLine(New String(" ", indent * 2) & "    " & tempArr.Name)

                    End If

                Next

                'lw.WriteLine(New String(" ", indent * 2) & " + Active Arrangement: " & child.OwningPart.ComponentAssembly.ActiveArrangement.Name)

                '*** end of code to process subassembly
            Else
                'this component has no children (it is a leaf node)
                'add any code specific to bottom level components
            End If
            reportComponentChildren(child, indent + 1)
        Next

    End Sub

    Public Function GetUnloadOption(ByVal dummy As String) As Integer

        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately

        '----Other unload options-------
        'Unloads the image when the NX session terminates
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

        'Unloads the image explicitly, via an unload dialog
        'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly
        '-------------------------------

    End Function

End Module

Re: Reference and Arrangement listing within all components

Valued Contributor
Valued Contributor

Thank you!

 

I realized those insert code were just comments. I attempted to run the code as C# code and not Visual basic.

When I ran it I got this error... Have any idea's what this might mean?

Also it outputs for a while but must hit a component that causes this error to happen.

Capture.JPG

 

 

Nevermind I found it was caused by components being suppressed and/or not loaded at all Smiley Happy
Worked like a charm! Thanks so much!!