Files
Demonstration of important custom properties methods
Code
'Written by Keith Rice
'CADSharp LLC
'www.cadsharp.com
'Written in SolidWorks 2011
'Working with custom properties in any document.
'Preconditions: Model is open.
'Postconditions: Certain custom properties are added, retrieved, set, deleted. Also, _
see immediate window.
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swCustPropMgr As SldWorks.CustomPropertyManager
Dim vCustPropNames As Variant
Dim strValOut As String
Dim strEvalValOut As String
Dim i As Integer
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swCustPropMgr = swModel.Extension.CustomPropertyManager("")
'add a custom property
swCustPropMgr.Add2 "Description", swCustomInfoText, "This is the description."
swCustPropMgr.Add2 "Author", swCustomInfoText, "Keith Rice"
swCustPropMgr.Add2 "Company", swCustomInfoText, "CADSharp LLC"
swCustPropMgr.Add2 "Mass", swCustomInfoText, Chr(34) & "SW-Mass@" & swModel.GetTitle & ".SLDPRT" & Chr(34)
'modify the custom property
swCustPropMgr.Set "Description", "This macro demonstrates use of ICustomPropertyManager."
'get the custom properties
vCustPropNames = swCustPropMgr.GetNames
For i = 0 To UBound(vCustPropNames)
swCustPropMgr.Get3 vCustPropNames(i), False, strValOut, strEvalValOut
Debug.Print "Custom property #" & i + 1
Debug.Print " Name: " & vCustPropNames(i)
Debug.Print " Type: " & swCustPropMgr.GetType2(vCustPropNames(i))
Debug.Print " Value: " & strValOut
Debug.Print " Evaluated value: " & strEvalValOut
Next i
'delete a custom properties
swCustPropMgr.Delete "Description"
End Sub