Hide Table of Contents

Get Hidden Components Filenames Example (C#)

This example shows how to get the filenames of the hidden components 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.
//-----------------------------------------------------------

using SolidWorks.Interop.sldworks;

using SolidWorks.Interop.swconst;

using System;

using System.Diagnostics;

using System.Windows.Forms;

namespace Macro1.csproj

{

    public partial class SolidWorksMacro

    {

        public void Main()

        {

           

            ModelDoc2 swModel;

            AssemblyDoc swAssembly;

            Boolean boolStatus;

 

            swModel = (ModelDoc2)swApp.ActiveDoc;

            swAssembly = (AssemblyDoc)swModel;

            boolStatus = swAssembly.HasUnloadedComponents();

            if (boolStatus == true)

            {

                object oPaths = null;

                object oRefdConfigs = null;

                object oReasons = null;

                object oDocTypes = null;

                object oNames = null;

 

                oNames = swAssembly.GetUnloadedComponentNames(out oPaths, out oRefdConfigs, out oReasons, out oDocTypes);

 

                string[] Paths = null;

                string[] RefdConfigs = null;

                int[] Reasons = null;

                int[] DocTypes = null;

                string[] Names = null;

 

                Paths = (string[])oPaths;

                RefdConfigs = (string[]) oRefdConfigs;

                Reasons = (int[]) oReasons;

                DocTypes =(int[]) oDocTypes;

                Names = (string[]) oNames;

            

                if (!(Paths is System.Array) & (RefdConfigs is System.Array) & (Reasons is System.Array) & (DocTypes is System.Array) & (Names is System.Array))

                {

                    MessageBox.Show("Error: Non-array parameter!");

                    Debug.Assert(false);

                    return;

                }

                if ((Paths.Length != RefdConfigs.Length) | (Paths.Length != Reasons.Length) | (Paths.Length != DocTypes.Length) | (Paths.Length != Names.Length))

                {

                    MessageBox.Show("Error: Lengths of the arrays do not match!");

                    Debug.Assert(false);

                    return;

                }

              

                for (int index = 0; index < Paths.Length; index++)

                {

                    string debugMessage = null;

                    debugMessage = index + ": ";

                    swDocumentTypes_e eDocType;

                    eDocType = (swDocumentTypes_e)(DocTypes[index]);

                    switch (eDocType)

                    {

                        case swDocumentTypes_e.swDocNONE:

                            debugMessage = debugMessage + "The document ";

                            break;

                        case swDocumentTypes_e.swDocPART:

                            debugMessage = debugMessage + "The part ";

                            break;

                        case swDocumentTypes_e.swDocASSEMBLY:

                            debugMessage = debugMessage + "The assembly ";

                            break;

                        case swDocumentTypes_e.swDocDRAWING:

                            debugMessage = debugMessage + "The drawing ";

                            break;

                        case swDocumentTypes_e.swDocSDM:

                            debugMessage = debugMessage + "The SDM ";

                            break;

                        default:

                            debugMessage = debugMessage + "The document is an unknown type ";

                            break;

                    }

                    debugMessage = debugMessage + Paths[index] + " was not loaded because it is ";

                    bool bUnloadedBecauseHidden = false;

                    if (Reasons[index] == 1)

                        bUnloadedBecauseHidden = true;

                    else

                        bUnloadedBecauseHidden = false;

 

                    if (bUnloadedBecauseHidden)

                    {

                        debugMessage = debugMessage + "hidden.";

                    }

                    else

                    {

                        debugMessage = debugMessage + "suppressed.";

                    }

                    Debug.Print(debugMessage);

                }

            }

           

        }

        /// <summary>

        /// The SldWorks swApp variable is pre-assigned for you.

        /// </summary>

        public SldWorks swApp;

    }

}



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 (C#)
*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.