Hide Table of Contents

Set Fully Resolved Assembly to Lightweight Example (VBA)

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

 

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

'

' Preconditions:

'       (1) Assembly is open.

'       (2) Assembly is fully resolved.

'

' Postconditions: Assembly is lightweight.

'

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

Option Explicit

Public Enum swDocumentTypes_e

    swDocNONE = 0

    swDocPART = 1

    swDocASSEMBLY = 2

    swDocDRAWING = 3

End Enum

Public Enum swComponentResolveStatus_e

    swResolveOk = 0

    swResolveAbortedByUser = 1

    swResolveNotPerformed = 2

    swResolveError = 3

End Enum

Public Enum swComponentSuppressionState_e

    swComponentSuppressed = 0

    swComponentLightweight = 1

    swComponentFullyResolved = 2

End Enum

Public Enum swSuppressionError_e

    swSuppressionBadComponent = 0

    swSuppressionBadState = 1

    swSuppressionChangeOk = 2

    swSuppressionChangeFailed = 3

End Enum

Sub SetComponentLightWeight _

( _

    sPadStr As String, _

    swComp As SldWorks.Component _

)

    Dim vChildArr                   As Variant

    Dim swChildComp                 As SldWorks.Component2

    Dim swChildModel                As SldWorks.ModelDoc2

    Dim nRetVal                     As Long

    Dim nDocType                    As Long

    Dim i                           As Long

    

    Debug.Print sPadStr & swComp.Name2 & " [" & CBool(swComp.Visible) & "]"

    

    vChildArr = swComp.GetChildren

    For i = 0 To UBound(vChildArr)

        Set swChildComp = vChildArr(i)

        

        ' Is NULL if another instance has been previously set to lightweight

        Set swChildModel = swChildComp.GetModelDoc

        If Not swChildModel Is Nothing Then

            nDocType = swChildModel.GetType

        Else

            nDocType = swDocNONE

        End If

        

        nRetVal = swChildComp.SetSuppression2(swComponentLightweight)

        If swDocPART = nDocType Or swDocNONE = nDocType Then

            Debug.Assert swResolveNotPerformed = nRetVal

        Else

            ' Cannot set a sub-assembly to lightweight; must set each part to lightweight

            Debug.Assert swDocASSEMBLY = swChildModel.GetType

            Debug.Assert swResolveError = nRetVal

        End If

        

        ' Recurse into this component

        SetComponentLightWeight sPadStr & "  ", swChildComp

    Next i

End Sub

Sub main()

    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swAssy                      As SldWorks.AssemblyDoc

    Dim swConfig                    As SldWorks.Configuration

    Dim swConfigMgr                 As SldWorks.ConfigurationManager

    Dim swRootComp                  As SldWorks.Component2

    Dim bRet                        As Boolean

    

    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swAssy = swModel

    Set swConfigMgr = swModel.ConfigurationManager

    Set swConfig = swConfigMgr.ActiveConfiguration

    Set swRootComp = swConfig.GetRootComponent

    Debug.Print "File = " & swModel.GetPathName

    SetComponentLightWeight "  ", swRootComp

    

    ' Update in-context features

    bRet = swModel.ForceRebuild3(False): Debug.Assert bRet

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:   Set Fully Resolved Assembly to Lightweight 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) 2013 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.