Work with Configurations Example (VBA)
This example shows how to work with new and derived configurations.
This example assumes that the SolidWorks parts document c:\calls5\part3.sldprt
exists.
'------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim Model As ModelDoc2
Dim boolstatus As Boolean
Sub main()
Set
swApp = Application.SldWorks
Set
Model = swApp.ActiveDoc
Dim
ConfigMgr As ConfigurationManager
Dim
C1a As Configuration
Dim
SelMgr As SelectionMgr
Set
SelMgr = Model.SelectionManager
Set
ConfigMgr = Model.ConfigurationManager
'
Create a new configuration named "Config1"
ConfigMgr.AddConfiguration "Config1",
"Config1 comment", "alternateName", 1, "",
"no description"
'
Create a derived configuration called "Config1 Derived" whose
parent configuration is "Config1"
ConfigMgr.AddConfiguration "Config1 Derived",
"Config1 Derived Comment", "Alternate Name", 1, "Config1",
"no description"
'
Show "Config1" and make it the active configuration
Model.ShowConfiguration2 ("Config1")
'
Get "Config1"
Set
C1a = Model.GetActiveConfiguration
'
Determine if the active configuration is a derived configuration
Debug.Print
C1a.IsDerived
Dim
VChildren As Variant
'
Determine the number of children configurations
Debug.Print
C1a.GetChildrenCount
'
Get all of the children configurations
VChildren
= C1a.GetChildren
Dim
CDerived As Configuration
Set
CDerived = VChildren(0)
'
Determine if the active configuration is a derived configuration
Debug.Print
CDerived.IsDerived
Dim
CParent As configuration
'
Get the parent configuration of the derived configuration
Set
CParent = CDerived.GetParent
'
Determine the number of configurations in this document
Debug.Print
swApp.GetConfigurationCount("C:\calls5\part3.sldprt")
Dim
V As Variant
'
Get the names of these configurations
V
= swApp.GetConfigurationNames("C:\calls5\part3.sldprt")
Dim
i As Long
For
i = 0 To UBound(V)
'
Print the names of these configurations
Debug.Print
V(i)
Next
End Sub