Hide Table of Contents

Work with Configurations Example (VBA)

This example shows how to work with new and derived configurations.

'--------------------------------------------------------------
' Preconditions:
' 1. Open public_documents\samples\tutorial\api\2012-sm.sldprt.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Creates two configurations, Config1 and Config1 Derived.
' 2. Gets whether each of these configurations are derived and the
'    number of children configurations for Config1.
' 3. Gets the number and names of the configurations in the part.
' 4. Examine the Immediate window.
'
' NOTE: Because the part is used elsewhere, do not save changes.
'---------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Model As ModelDoc2
Dim ConfigMgr As ConfigurationManager
Dim C1a As Configuration
Dim SelMgr As SelectionMgr
Dim CDerived As Configuration
Dim CParent As Configuration
Dim V As Variant
Dim i As Long

Sub main()
    Set swApp = Application.SldWorks
    Set Model = swApp.ActiveDoc
    Set SelMgr = Model.SelectionManager
    Set ConfigMgr = Model.ConfigurationManager    
    ' Create a new configuration named Config1
    ConfigMgr.AddConfiguration2 "Config1", "Config1 comment", "alternateName", 1, "", "no description", True

    ' Create a derived configuration called "Config1 Derived" whose parent configuration is "Config1"
    ConfigMgr.AddConfiguration2 "Config1 Derived", "Config1 Derived Comment", "Alternate Name", 1, "Config1", "no description", True

    ' Add a rebuild and save mark to all configurations
    bRet = ConfigMgr.AddRebuildSaveMark(2, Nothing)

    ' Display all configuration nodes expanded in the top pane
    ConfigMgr.SetExpanded 0, True

    ' Show Config1 and make it the active configuration
    Model.ShowConfiguration2 ("Config1")

    ' Select the configuration to preview in the bottom pane
    boolstatus = Model.Extension.SelectByID2("Config1", "CONFIGURATIONS", 0, 0, 0, False, 0, Nothing, 0)
    ConfigMgr.ShowPreview = True

    ConfigMgr.ShowConfigurationDescriptions = True
    ConfigMgr.ShowConfigurationNames = True

    ' Get Config1
    Set C1a = Model.GetActiveConfiguration
    ' Determine if the active configuration is a derived configuration
    Debug.Print C1a.Name & " configuration derived? " & C1a.IsDerived
    Dim VChildren As Variant
    
    ' Determine the number of children configurations
    Debug.Print "  Number of children configurations: " & C1a.GetChildrenCount

    ' Get all of the children configurations
    VChildren = C1a.GetChildren
    Set CDerived = VChildren(0)

    ' Determine if the active configuration is a derived configuration
    Debug.Print CDerived.Name & " configuration derived? " & CDerived.IsDerived
    
    ' Get the parent configuration of the derived configuration
    Set CParent = CDerived.GetParent
    ' Determine the number of configurations in this document
    Debug.Print "Number of configurations in part: " & swApp.GetConfigurationCount("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\2012-sm.sldprt")
 
    ' Get the names of these configurations
    V = swApp.GetConfigurationNames("C:\Users\Public\Documents\SOLIDWORKS\SOLIDWORKS 2018\samples\tutorial\api\2012-sm.sldprt")
    
    Debug.Print "Names of configurations in part:"
    For i = 0 To UBound(V)
        ' Print the names of these configurations
        Debug.Print "  " & V(i)
    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:   Work with Configurations 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) 2019 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.