Files
Get all custom property names and values
Code
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Written in SolidWorks 2011
'Counts and lists all configurations in model, custom and config specific
'Also includes configuration traversal
'Precondition: part is open
'Postconditions: see immediate window
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim vConfigNamesArray As Variant
Dim vConfigName As Variant
Dim vName As Variant
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim strValue As String
Dim strResValue As String
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
'error handling
If swModel Is Nothing Then
Debug.Print "Open a document."
End
End If
'entire model
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
Debug.Print "Custom: " & swCustPropMgr.Count
vCustPropNames = swCustPropMgr.GetNames
If IsEmpty(vCustPropNames) = False Then
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, strValue, strResValue
Debug.Print " " & vName & " " & strValue & " " & strResValue
Next vName
End If
'You can deal with config specific custom props by setting swCustPropMgr equal to the CustomPropertyManager _
from a specific configuration
'METHOD ONE - do not get custom property manager from configuration
Call Method1
'METHOD TWO - get custom property manager from configuration
'Call Method2
End Sub
Sub Method1()
vConfigNamesArray = swModel.GetConfigurationNames
For Each vConfigName In vConfigNamesArray
Set swCustPropMgr = swModel.Extension.CustomPropertyManager(vConfigName)
Debug.Print vConfigName & ": " & swCustPropMgr.Count
vCustPropNames = swCustPropMgr.GetNames
If IsEmpty(vCustPropNames) = False Then
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, strValue, strResValue
Debug.Print " " & vName & " " & strValue & " " & strResValue
Next vName
End If
Next vConfigName
End Sub
Sub Method2()
Dim swConfigMgr As SldWorks.ConfigurationManager
Dim swConfig As SldWorks.Configuration
Set swConfigMgr = swModel.ConfigurationManager
vConfigNamesArray = swModel.GetConfigurationNames
For Each vConfigName In vConfigNamesArray
Set swConfig = swModel.GetConfigurationByName(vConfigName)
Set swCustPropMgr = swConfig.CustomPropertyManager
Debug.Print vConfigName & ": " & swCustPropMgr.Count
vCustPropNames = swCustPropMgr.GetNames
If IsEmpty(vCustPropNames) = False Then
For Each vName In vCustPropNames
swCustPropMgr.Get3 vName, True, strValue, strResValue
Debug.Print " " & vName & " " & strValue & " " & strResValue
Next vName
End If
Next vConfigName
End Sub
'Another way to get the configuration:
'Set swConfig = swConfigMgr.ActiveConfiguration