Delete Attribute Example (VBA)
This example shows how to delete the selected attribute.
'------------------------------------
'
' Preconditions: Model document is open and an attribute
is selected.
'
' Postconditions: After deleting an attribute, it's name
is blank. You
' must
still follow the rules of COM reference counting.
'
'-------------------------------------
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
swAttr As
SldWorks.Attribute
Dim
bRet As
Boolean
Set
swApp = CreateObject("SldWorks.Application")
Set
swModel = swApp.ActiveDoc
Set
swSelMgr = swModel.SelectionManager
Set
swFeat = swSelMgr.GetSelectedObject5(1)
Set
swAttr = swFeat.GetSpecificFeature2
Debug.Print
"File = " & swModel.GetPathName
Debug.Print
" Feature
name =
" & swAttr.GetName
bRet
= swAttr.Delete(True)
Debug.Assert
bRet
'
Returns a blank string
Debug.Print
" Attribute
name =
" & swAttr.GetName
End Sub