Hide Table of Contents

Get Hidden Components Filenames Example (VBA)

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

'-----------------------------------------------------------
' Preconditions:
' 1. In SOLIDWORKS, click File > Open, and browse to
'    public_documents\samples\tutorial\routing-pipes.
' 2. Click ball valve with flanges.sldasm > Mode >
'    Large Design Review > Open > OK.
'
'    NOTE: If the path to the Design Library does not exist,
'    then multiple dialogs informing you that SOLIDWORKS is unable
'    to locate might be displayed some components. Click No or OK
'    to close these dialogs.
'
' 3. Click ball valve-1 in the FeatureManager design tree
'    and click Selective Open > Selective Open > Selected components >
'    Open Selected > OK.
'
'    NOTE: Only the selected components are loaded. Components
'    not selected are not loaded and not visible in the
'    SOLIDWORKS graphics area.
'
' 4. Open the Immediate window.
'
' Postconditions:
' 1. Does not load the slip on weld flange components because
'    they are hidden.
' 2. Examine the graphics area and Immediate window.
'
' NOTE: Because this assembly elsewhere, do not save changes.
'-----------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Sub main()
    Set swApp = Application.SldWorks
    Dim swAssembly As SldWorks.AssemblyDoc
    Set swAssembly = swApp.ActiveDoc
    If swAssembly.HasUnloadedComponents Then
        Dim vPaths As Variant
        Dim vRefdConfigs As Variant
        Dim vReasons As Variant
        Dim vDocTypes As Variant
        Dim vNames As Variant
        vNames = swAssembly.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 & vPaths(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 Components Filenames 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) 2022 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.