cancel
Showing results for 
Search instead for 
Did you mean: 

Force Loading Suppressed Components

Builder
Builder

I have Component "A"

Under component "A" there are several children. Some of them are suppressed and some of them are not. 

How do I force load the suppressed components?

1 REPLY

Re: Force Loading Suppressed Components

Solution Partner Creator Solution Partner Creator
Solution Partner Creator

I use this:

' NX 11.0.1.11
' Journal created by infodba on Tue May 30 12:19:21 2017 Central Europe Daylight Time
'
Imports System
Imports System.Xml
Imports NXOpen
Imports NXOpen.Assemblies
Imports NXOpen.BlockStyler
Imports NXOpen.Features
Imports NXOpen.UF
Imports NXOpen.Utilities

Module NXJournal

    Dim theSession As Session = NXOpen.Session.GetSession
    Dim theUI As UI = UI.GetUI()
    Dim theUfSession As UFSession = NXOpen.UF.UFSession.GetUFSession()
    Dim workPart As Part = theSession.Parts.Work
    Dim lw As ListingWindow = theSession.ListingWindow
	
Sub Main (ByVal args() As String) 

Dim displayPart As NXOpen.Part = theSession.Parts.Display

kezdes()
 

End Sub

Function kezdes()


        Dim wp As Part
        wp = theSession.Parts.Work

        Dim markId1 As NXOpen.Session.UndoMarkId
        markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Invisible, "Open Assembly")

        Dim markId2 As NXOpen.Session.UndoMarkId
        markId2 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Open Assembly")

        Dim componentsToOpen1(0) As NXOpen.Assemblies.Component
        componentsToOpen1(0) = wp.ComponentAssembly.RootComponent
        Dim option1 As Boolean = False
        theSession.Parts.LoadOptions.UsePartialLoading = option1

        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
        Dim partLoadStatus1 As NXOpen.PartLoadStatus
        partLoadStatus1 = wp.ComponentAssembly.OpenComponents(NXOpen.Assemblies.ComponentAssembly.OpenOption.WholeAssembly, componentsToOpen1, openStatus1)

        partLoadStatus1.Dispose()
        theSession.DeleteUndoMark(markId1, Nothing)

        assy_fa_m()


        Return 0
    End Function

    Function assy_fa_m()

        'If Args.length = 0 And theSession.Parts.Work Is Nothing Then
        'lw.WriteLine("Part file argument expected or work part required")
        'Return
        'End If

        theUfSession.Ui.SetStatus("Loading the structure...")

        Try
            Dim part1 As Part
            'If Args.length = 0 Then
            part1 = theSession.Parts.Work
            'Echo("part1: " & part1.Tag)
            'Else
            'Dim loadStatus1 As PartLoadStatus = Nothing
            'part1 = theSession.Parts.OpenDisplay(Args(0), loadStatus1)
            'loadStatus1.Dispose()
            'End If

            Dim c As Component = part1.ComponentAssembly.RootComponent
            
			
			Dim fullpath As String = ""
            Dim ins_name As String = ""
            Dim ref_name As String = ""
            Dim origo(2) As Double
            Dim csys_m(8) As Double
            Dim trans(3, 3) As Double
            theUfSession.Assem.AskComponentData(c.Tag, fullpath, ref_name, ins_name, origo, csys_m, trans)
            ShowAssemblyTree_m(c, "")


        Catch ex As Exception
            'lw.WriteLine("Failed: " & e.Message)
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
        End Try

        Return 0
    End Function

    Function ShowAssemblyTree_m(ByVal c As Component, ByVal indent As String)

                Dim partLoadStatus3 As UFPart.LoadStatus
        Dim fullpath As String = ""
        Dim ins_name As String = ""
        Dim ref_name As String = ""
        Dim origo(2) As Double
        Dim csys_m(8) As Double
        Dim trans(3, 3) As Double

        lw.Open()

        Dim componentsToOpen1(0) As NXOpen.Assemblies.Component

        Dim partLoadStatus1 As NXOpen.PartLoadStatus
        Dim hiba As Boolean = False

        Try
            theUfSession.Ui.SetStatus("Loading the structure...")

            Dim children As Component() = c.GetChildren()
            Dim newIndent As String = ""

            For Each child As Component In children
			lw.writeline("child: " & child.tag)
                componentsToOpen1(0) = child
				
				theUfSession.Assem.AskComponentData(child.Tag, fullpath, ref_name, ins_name, origo, csys_m, trans)

                If indent.Length = 0 Then
                    newIndent = "."

                    Dim load As Integer = 0
                    load = theufsession.Part.IsLoaded(fullpath)
                    lw.WriteLine("load: " & load)
                    If load = 2 Then
                        partLoadStatus1 = child.Prototype.OwningPart.LoadThisPartFully()
                        'reportPartLoadStatus(partLoadStatus1)
                        partLoadStatus1.Dispose()
                    End If

                    If load = 0 Then
                        lw.WriteLine("load0")
                        theufsession.Part.OpenQuiet(fullpath, child.Tag, partLoadStatus3)
                        'lw.WriteLine("open")
                        Dim option1 As Boolean
                        option1 = theSession.Parts.LoadOptions.UsePartialLoading
                        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
                        Dim partLoadStatus2 As NXOpen.PartLoadStatus
                        partLoadStatus2 = theSession.Parts.Work.ComponentAssembly.OpenComponents(NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, componentsToOpen1, openStatus1)
                        partLoadStatus2.Dispose()
                        partLoadStatus1 = componentsToOpen1(0).Prototype.OwningPart.LoadThisPartFully()
                        'reportPartLoadStatus(partLoadStatus1)
                        partLoadStatus1.Dispose()
                    End If

                Else
                    newIndent = indent & "."

                    Dim load As Integer = 0
                    load = theufsession.Part.IsLoaded(fullpath)
                    lw.WriteLine("load+" & load)
                    If load = 2 Then
                        partLoadStatus1 = child.Prototype.OwningPart.LoadThisPartFully()
                        'reportPartLoadStatus(partLoadStatus1)
                        partLoadStatus1.Dispose()
                    End If

                    If load = 0 Then
                        lw.WriteLine("load0-")
                        theufsession.Part.OpenQuiet(fullpath, child.Tag, partLoadStatus3)
                        lw.WriteLine("open-")
                        Dim option1 As Boolean
                        option1 = theSession.Parts.LoadOptions.UsePartialLoading
                        Dim openStatus1() As NXOpen.Assemblies.ComponentAssembly.OpenComponentStatus
                        Dim partLoadStatus2 As NXOpen.PartLoadStatus
                        partLoadStatus2 = theSession.Parts.Work.ComponentAssembly.OpenComponents(NXOpen.Assemblies.ComponentAssembly.OpenOption.ComponentOnly, componentsToOpen1, openStatus1)
                        partLoadStatus2.Dispose()
                        partLoadStatus1 = componentsToOpen1(0).Prototype.OwningPart.LoadThisPartFully()
                        'reportPartLoadStatus(partLoadStatus1)
                        partLoadStatus1.Dispose()
                    End If

                End If
                'lw.WriteLine(newIndent & child.DisplayName)

                'End If


                'Dim ch As Part = child.OwningPart
                'ch = theSession.Parts.Work

                'Echo("/////////////////////////")
                'Exit For

                ShowAssemblyTree_m(child, newIndent)
                'Exit For
            Next

        Catch ex As Exception
            'lw.WriteLine("Failed_: " & e.Message)
            'MsgBox(e.Message)
            theUI.NXMessageBox.Show("Block Styler", NXMessageBox.DialogType.Error, ex.ToString)
        End Try

        Return 0
    End Function
End Module

(view in My Videos)
 

Attila Szepesi, Application Engineer, graphIT Ltd.
Production: NX11.0.2 | TcUA 11.2 MP2 Patch 1 (11.2.2.1)
Development: VB.NET Testing: NX12.0