Add and Get Custom Properties Example (VBA)
This example shows how to add a custom property to and gets the custom
properties assigned to a weldment feature.
'------------------------------------------
' Preconditions:
' 1. Model document is open.
' 2. Weldment feature is selected.
'
' Postconditions: Custom property named Date
added is added to the
' selected
weldment feature.
'----------------------------------------
Option Explicit
Sub main()
Dim
swApp As
SldWorks.SldWorks
Dim
swModel As
SldWorks.ModelDoc2
Dim
swSelMgr As
SldWorks.SelectionMgr
Dim
swFeat As
SldWorks.feature
Dim
swCustPropMgr As
SldWorks.CustomPropertyManager
Dim
nRetVal As
Long
Dim
vNameArr As
Variant
Dim
vName As
Variant
Dim
bRet As
Boolean
Set
swApp = Application.SldWorks
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swFeat = swSelMgr.GetSelectedObject6(1,
0)
Set
swCustPropMgr = swFeat.CustomPropertyManager
'
Feature::GetTypeName
'
"SubWeldFolder"
'
"WeldmentFeature"
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" "
& swFeat.Name & "
[" & swFeat.GetTypeName
& "]"
'
Add custom property
bRet
= swCustPropMgr.Add("Date
added", "Date, "17-Apr-2005")
'
Get all custom properties; Date added
is the last one in the list
vNameArr
= swCustPropMgr.GetNames: If IsEmpty(vNameArr)
Then Exit Sub
For
Each vName In vNameArr
Debug.Print
" "
& vName & " [" & swCustPropMgr.GetType(vName)
& "] = " & swCustPropMgr.Get(vName)
Next
vName
End Sub
'------------------------------------------