Hide Table of Contents

Get Hidden Children Component Names Example (VBA)

This example shows how to get the names of the hidden components in an assembly document.

'-----------------------------------------------------------

' Preconditions:

' 1. In SolidWorks, click File > Open, and browse to

'    <SolidWorks_install_dir>\samples\tutorial\routing-pipes.

' 2. Select finalskid.sldasm, select the Quick view/Selective

'    open check box, and click Open.

'

' NOTE: If the path to the Design Library (click Tools > Options >

'       File Locations and select Design Library in Show folders for)

'       does not exist, then multiple dialogs might be displayed

'       informing you that SolidWorks is unable to locate

'       some components. Click No or OK to close these dialogs.

'

' 3. Expand all nodes in the FeatureManager design tree,

'    select all upper-level components except Cabinet<1>(Default),

'    and click Open Selected.

' 4. Click OK.

' 5. Run the macro and look at the results in the Immediate

'    Window in the IDE.

'

' NOTE: Only the selected components are loaded. The

'       Cabinet<1>(Default) component and its

'       children components (cabinet-1, door-1,

'       and door-2)are not loaded and are not visible

'       in the SolidWorks graphics area. See the

'       SolidWorks Help for details about selectively

'       opening assembly documents.

'

' Postconditions: The Cabinet<1>(Default) component and its

'                children components (cabinet-1, door-1,

'                and door-2) are not loaded.

'

' IMPORTANT: Because this assembly document is used in

' a SolidWorks online tutorial, when you close the assembly

' document do not save any changes, if prompted.

'-----------------------------------------------------------

Option Explicit

 

Dim swApp As SldWorks.SldWorks

 

Sub main()

 

    Set swApp = Application.SldWorks

    Dim swAssembly As SldWorks.AssemblyDoc

    Set swAssembly = swApp.ActiveDoc

    

    Dim swComponent As SldWorks.Component2

    Set swComponent = swAssembly.GetComponentByName("Cabinet-1")

    If swComponent.HasUnloadedComponents Then

        Dim vPaths As Variant

        Dim vRefdConfigs As Variant

        Dim vReasons As Variant

        Dim vDocTypes As Variant

        Dim vNames As Variant

        vNames = swComponent.GetUnloadedComponentNames(vPaths, vRefdConfigs, vReasons, vDocTypes)

 

        If IsEmpty(vPaths) Or IsEmpty(vRefdConfigs) Or IsEmpty(vReasons) Or IsEmpty(vDocTypes) Or IsEmpty(vNames) Then

            MsgBox "Error: Empty VARIANT parameter!"

            Debug.Assert False

            Exit Sub

        End If

  

        If Not (IsArray(vPaths) And IsArray(vRefdConfigs) And IsArray(vReasons) And IsArray(vDocTypes) And IsArray(vNames)) Then

            MsgBox "Error: Non-array VARIANT parameter!"

            Debug.Assert False

            Exit Sub

        End If

 

        If (LBound(vPaths) <> LBound(vRefdConfigs)) Or (LBound(vPaths) <> LBound(vReasons)) Or (LBound(vPaths) <> LBound(vDocTypes)) Or (LBound(vPaths) <> LBound(vNames)) Then

            MsgBox "Error: Array lower bounds do not match!"

            Debug.Assert False

            Exit Sub

        End If

 

        If (UBound(vPaths) <> UBound(vRefdConfigs)) Or (UBound(vPaths) <> UBound(vReasons)) Or (UBound(vPaths) <> UBound(vDocTypes)) Or (UBound(vPaths) <> UBound(vNames)) Then

            MsgBox "Error: Array upper bounds do not match!"

            Debug.Assert False

            Exit Sub

        End If

 

        Dim index As Integer

        For index = LBound(vNames) To UBound(vNames)

            Dim debugMessage As String

            debugMessage = index & ": "

            Dim eDocType As swDocumentTypes_e

            eDocType = vDocTypes(index)

            Select Case eDocType

            Case swDocNONE

                debugMessage = debugMessage & "The document "

            Case swDocPART

                debugMessage = debugMessage & "The part "

            Case swDocASSEMBLY

               debugMessage = debugMessage & "The assembly "

            Case swDocDRAWING

                debugMessage = debugMessage & "The drawing "

            Case swDocSDM

                debugMessage = debugMessage & "The SDM "

            Case Else

               debugMessage = debugMessage & "The document of unknown type "

            End Select

          debugMessage = debugMessage & vNames(index) & " was not loaded because it is "

            Dim bUnloadedBecauseHidden As Boolean

            bUnloadedBecauseHidden = vReasons(index)

            If bUnloadedBecauseHidden Then

                debugMessage = debugMessage & "hidden. "

            Else

                debugMessage = debugMessage & "suppressed."

            End If

            Debug.Print debugMessage

        Next

    End If

    

    

End Sub



Provide feedback on this topic

SOLIDWORKS welcomes your feedback concerning the presentation, accuracy, and thoroughness of the documentation. Use the form below to send your comments and suggestions about this topic directly to our documentation team. The documentation team cannot answer technical support questions. Click here for information about technical support.

* Required

 
*Email:  
Subject:   Feedback on Help Topics
Page:   Get Hidden Children Component Names Example (VBA)
*Comment:  
*   I acknowledge I have read and I hereby accept the privacy policy under which my Personal Data will be used by Dassault Systèmes

Print Topic

Select the scope of content to print:

x

We have detected you are using a browser version older than Internet Explorer 7. For optimized display, we suggest upgrading your browser to Internet Explorer 7 or newer.

 Never show this message again
x

Web Help Content Version: API Help (English only) 2010 SP05

To disable Web help from within SOLIDWORKS and use local help instead, click Help > Use SOLIDWORKS Web Help.

To report problems encountered with the Web help interface and search, contact your local support representative. To provide feedback on individual help topics, use the “Feedback on this topic” link on the individual topic page.