Hide Table of Contents

Set Fully Resolved Assembly to Lightweight Example (C#)

This example shows how to set a fully resolved assembly to lightweight.

//----------------------------------------------------------------
// Preconditions:
// 1. Open a fully resolved assembly document.
// 2. Open the Immediate window.
//
// Postconditions:
// 1. Sets all assembly components to lightweight.
// 2. Examine the Immediate window and FeatureManager design tree.
//----------------------------------------------------------------
using SolidWorks.Interop.sldworks;
using SolidWorks.Interop.swconst;
using System.Runtime.InteropServices;
using System;
using System.Diagnostics;
 
namespace SetSuppression2.csproj
{
    public partial class SolidWorksMacro
    {
 
        public void Main()
        {
            ModelDoc2 swModel = default(ModelDoc2);
            AssemblyDoc swAssy = default(AssemblyDoc);
            Configuration swConfig = default(Configuration);
            ConfigurationManager swConfigMgr = default(ConfigurationManager);
            Component2 swRootComp = default(Component2);
            bool bRet = false;
            string sPadStr = "  ";
 
            swModel = (ModelDoc2)swApp.ActiveDoc;
            swAssy = (AssemblyDoc)swModel;
            swConfigMgr = (ConfigurationManager)swModel.ConfigurationManager;
            swConfig = (Configuration)swConfigMgr.ActiveConfiguration;
            swRootComp = (Component2)swConfig.GetRootComponent3(true);
            Debug.Print("File = " + swModel.GetPathName());
            SetComponentLightWeight(sPadStr, swRootComp);
 
            // Update in-context features
            bRet = swModel.ForceRebuild3(false);
            Debug.Assert(bRet);
 
        }
 
        public void SetComponentLightWeight(string sPadStr, Component2 swComp)
        {
            object[] vChildArr = null;
            Component2 swChildComp = default(Component2);
            ModelDoc2 swChildModel = default(ModelDoc2);
            int nRetVal = 0;
            int nDocType = 0;
            int i = 0;
 
            Debug.Print(sPadStr + swComp.Name2 + " [" + Convert.ToBoolean(swComp.Visible) + "]");
            vChildArr = (object[])swComp.GetChildren();
            for (i = 0; i < vChildArr.Length; i++)
            {
                swChildComp = (Component2)vChildArr[i];
                // Is null if another instance has been previously set to lightweight
                swChildModel = (ModelDoc2)swChildComp.GetModelDoc2();
                if ((swChildModel != null))
                {
                    nDocType = swChildModel.GetType();
                }
                else
                {
                    nDocType = (int)swDocumentTypes_e.swDocNONE;
                }
                nRetVal = swChildComp.SetSuppression2((int)swComponentSuppressionState_e.swComponentLightweight);
                if ((int)swDocumentTypes_e.swDocPART == nDocType | (int)swDocumentTypes_e.swDocNONE == nDocType)
                {
                    Debug.Assert((int)swComponentResolveStatus_e.swResolveNotPerformed == nRetVal);
                }
                else
                {
                    // Cannot set a sub-assembly to lightweight; must set each part to lightweight
                    Debug.Assert((int)swDocumentTypes_e.swDocASSEMBLY == swChildModel.GetType());
                    Debug.Assert((int)swComponentResolveStatus_e.swResolveError == nRetVal);
                }
                // Recurse into this component
                SetComponentLightWeight(sPadStr + "  ", swChildComp);
 
            }
 
        }
 
        /// <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:   Set Fully Resolved Assembly to Lightweight 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) 2018 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.