Hide Table of Contents

Are the Assembly Configurations Loaded Example (VBA)

This example shows how to find out if the configurations in an assembly are loaded, whether the configurations need to be updated and rebuilt, and the configuration types.

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

' Preconditions:

' 1. Assembly document opened by the macro exists.

' 2. Open the Immediate window.

'

' Postconditions:

' 1. All configurations are loaded.

' 2. Examine the Immediate window to see the states of the

'    configurations.

'

' NOTE: Because the assembly document is used elsewhere, do not save

' the document when you close it.

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

Option Explicit

 

Dim swApp As SldWorks.SldWorks

Dim swModel As SldWorks.ModelDoc2

Dim swConfiguration As SldWorks.Configuration

Dim swConfigurationMgr As SldWorks.ConfigurationManager

Dim vConfNameArr As Variant

Dim vConfName As Variant

Const sDocFilename As String = "C:\Program Files\SolidWorks Corp\SolidWorks\samples\tutorial\pdmworks\speaker.sldasm"

Dim boolstatus As Boolean

Dim nErrors As Long

Dim nWarnings As Long

 

Sub main()

 

    Set swApp = Application.SldWorks

 

    ' Open document; exit if it doesn't open

    Set swModel = swApp.OpenDoc6(sDocFilename, swDocASSEMBLY, swOpenDocOptions_Silent, "", nErrors, nWarnings)

    If swModel Is Nothing Then

        Exit Sub

    Else

        Debug.Print "File = " & swModel.GetPathName

        Debug.Print ""

    End If

    

    Set swConfigurationMgr = swModel.ConfigurationManager

    Set swConfiguration = swConfigurationMgr.ActiveConfiguration

    vConfNameArr = swModel.GetConfigurationNames

 

    Debug.Print "Traverse assembly without activating other configurations..."

    For Each vConfName In vConfNameArr

        Set swConfiguration = swModel.GetConfigurationByName(vConfName)

        Debug.Print "  Name of the configuration: " & swConfiguration.Name

        Debug.Print "    Is the configuration loaded? " & swConfiguration.IsLoaded

        Debug.Print "    Does the configuration need to be updated? " & swConfiguration.IsDirty

        Debug.Print "    Does the configuration need to be rebuilt? " & swConfiguration.NeedsRebuild

        Debug.Print "    What is the configuration type? " & swConfiguration.Type

    Next

    

    Debug.Print ""

    

    ' Traverse the assembly again, but this time activate all

    ' configurations, which loads them

    Debug.Print "Traverse assembly and activate all configurations..."

        For Each vConfName In vConfNameArr

        Set swConfiguration = swModel.GetConfigurationByName(vConfName)

        boolstatus = swModel.ShowConfiguration2(vConfName)

        Set swConfiguration = swConfigurationMgr.ActiveConfiguration

        Debug.Print "  Name of the configuration: " & swConfiguration.Name

        Debug.Print "    Is the configuration loaded? " & swConfiguration.IsLoaded

        Debug.Print "    Does the configuration need to be updated? " & swConfiguration.IsDirty

        Debug.Print "    Does the configuration need to be rebuilt? " & swConfiguration.NeedsRebuild

        Debug.Print "    What is the configuration type? " & swConfiguration.Type

    Next

 

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:   Are the Assembly Configurations Loaded 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.