Get Custom Properties for Configuration Example (VBA)
This example shows how to get the names, types, values, and resolved
values of the active configuration's custom properties. It also shows
how to add a custom property to the configuration.
'---------------------------------------------------------------------------
' Preconditions: Open a part document containing a
'
configuration that has custom properties.
'
' Postconditions: A date custom property is added to the configuration.
'---------------------------------------------------------------------------
Option Explicit
Dim swApp
As SldWorks.SldWorks
Dim swModel
As SldWorks.ModelDoc2
Dim swConfigMgr
As SldWorks.ConfigurationManager
Dim swConfig
As SldWorks.Configuration
Dim swCustPropMgr As
SldWorks.CustomPropertyManager
Dim nNbrProps
As Long
Dim j
As Long
Dim retVal
As Long
Dim vPropNames
As Variant
Dim valOut
As String
Dim resolvedValOut As String
Dim custPropType As
Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swConfigMgr = swModel.ConfigurationManager
Set swConfig = swConfigMgr.ActiveConfiguration
Debug.Print "Name of this configuration:
" & swConfig.Name
Set swCustPropMgr = swConfig.CustomPropertyManager
' Get the number of custom properties for
this configuration
nNbrProps = swCustPropMgr.Count
Debug.Print "Number of properties for this configuration:
" & nNbrProps
' Add a date custom property to this
configuration
retVal = swCustPropMgr.Add2("Date ", swCustomInfoDate,
"22-Oct-2012")
' Get the new number of custom properties
for this configuration
nNbrProps = swCustPropMgr.Count
Debug.Print "New number of properties for this configuration:
" & nNbrProps
' Get the names of the custom properties
vPropNames = swCustPropMgr.GetNames
' For each custom property, get and print its
type, value, and resolved value
For j = 0 To nNbrProps - 1
swCustPropMgr.Get2
vPropNames(j), valOut, resolvedValOut
custPropType = swCustPropMgr.GetType2(vPropNames(j))
Debug.Print " Name,
swCustomInfoType_e value, and resolved value: " & vPropNames(j) & ", ";
custPropType & ", " & resolvedValOut
Next j
End Sub