> Get Hidden Components Filenames Example (C#)
Welcome
Getting Started
SolidWorks API Help
FeatureWorks API Help
SolidWorks Document Manager API Help
eDrawings API Help
SolidWorks Routing API Help
SolidWorks Simulation API Help
SolidWorks Utilities API Help
SolidWorks Workgroup PDM API Help
Hide Table of Contents Show Table of Contents

Get Hidden Components Filenames Example (C#)

This example shows how to get the filenames of the hidden components in an assembly. This example also shows how to call a method that returns multiple objects and how to cast those objects to arrays (i.e., IAssemblyDoc::GetUnloadedComponentNames).

//-----------------------------------------------------------

// Preconditions:

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

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

// 2. Select ball valve with flanges.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. Select Ball Valve-1 in the FeatureManager design tree

//     and click Open Selected.

//

// NOTE: Only the selected components are loaded. Components

//       not selected are not loaded and not visible in

//       the SolidWorks graphics area. See the

//       SolidWorks Help for details about selectively opening

//       assembly documents.

// 4. Click OK.

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

//          Window in the IDE.

//

// Postconditions: Both slip on weld flange components are hidden.

//

// NOTE: Because this assembly document is used in

// a SolidWorks online tutorial, when you close the assembly

// document do not save any changes, if prompted.

//-----------------------------------------------------------

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;

    }

}



Related SolidWorks Forum Content

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:  
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) 2012 SP05

The search functionality within the web help is in a beta test phase and you may experience periodic delays or interruptions in its performance. These are the normal and ordinary features of a beta test and shall not under any circumstances give rise to any liability on the part of DS SolidWorks or its licensors. The topics within the Web-based help are not beta topics; they document API Help (English only) 2012 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.