Hide Table of Contents

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.
' Postconditions:
' 1. Inspect the Immediate window.
' 2. A date custom property is added to the part's configuration.
' 3. The custom property is deleted from the configuration.

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
    vPropNames = cusPropMgr.GetNames

   ' For each custom property, print its type, value, and resolved value
    For j = 0 To nNbrProps - 1
        lRetVal = cusPropMgr.GetAll2(vPropNames, vPropTypes, vPropValues, resolved)
        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

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

Subject:   Feedback on Help Topics
Page:   Get Custom Properties for Configuration Example (VBA)
*   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:


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

Web Help Content Version: API Help (English only) 2014 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.