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:
' 1. Open a part document.
' 2. Open the Immediate window.
'
' Postconditions:
' 1. Adds a date custom property to the part's configuration.
' 2. Deletes the custom property from the configuration.
' 3. Examine the Immediate window.
'---------------------------------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim config As SldWorks.Configuration
Dim cusPropMgr As SldWorks.CustomPropertyManager
Dim lRetVal As Long
Dim vPropNames As Variant
Dim vPropTypes As Variant
Dim vPropValues As Variant
Dim ValOut As String
Dim ResolvedValOut As String
Dim wasResolved As Boolean
Dim resolved As Variant
Dim nNbrProps As Long
Dim j As Long
Dim custPropType As Long
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set config = swModel.GetActiveConfiguration
Set cusPropMgr = config.CustomPropertyManager
lRetVal = cusPropMgr.Add3("ADATE",
swCustomInfoType_e.swCustomInfoDate, "4-13-59",
swCustomPropertyAddOption_e.swCustomPropertyDeleteAndAdd)
lRetVal = cusPropMgr.Get5("ADATE", False, ValOut,
ResolvedValOut, wasResolved)
lRetVal = cusPropMgr.Set2("ADATE", "4-13-89")
' Get the number of custom properties for
this configuration
nNbrProps = cusPropMgr.Count
Debug.Print "Number of properties for this configuration:
" & nNbrProps
' Get the names of the custom properties
lRetVal = cusPropMgr.GetAll2(vPropNames,
vPropTypes, vPropValues, resolved)
' For each custom property, print its type,
value, and resolved value
For j = 0 To nNbrProps - 1
custPropType = cusPropMgr.GetType2(vPropNames(j))
Debug.Print " Name,
swCustomInfoType_e value, and resolved value: " & vPropNames(j) & ", ";
custPropType & ", " & ResolvedValOut
Next j
lRetVal = cusPropMgr.Delete2("ADATE")
' Get the number of custom properties for this configuration
nNbrProps = cusPropMgr.Count
Debug.Print "Number of properties for this configuration:
" & nNbrProps
End Sub