Get Comments in Comments Folder Example (VBA)
This example shows how to get the comments in a Comments folder.
'------------------------------
'
' Preconditions: Model document is open and has a Comments
folder.
'
' Postconditions: None
'
'-------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModelDoc As SldWorks.AssemblyDoc
Dim swFeat As SldWorks.Feature
Dim swCommentFolder As SldWorks.CommentFolder
Dim swComment As SldWorks.Comment
Dim nbrComments As Long
Dim sFeatType As String
Dim vComments As Variant
Dim i As Long
Sub main()
Set swApp = Application.SldWorks
Set swModelDoc = swApp.ActiveDoc
' Traverse the FeatureManager design tree for Comments
folder
'
Get first feature in FeatureManager design tree
Set
swFeat = swModelDoc.FirstFeature
Do
While Not swFeat Is Nothing
sFeatType
= swFeat.GetTypeName
'Debug.Print
sFeatType
'
If Comments folder, get its data
If
sFeatType = "CommentsFolder" Then
Set
swCommentFolder = swFeat.GetSpecificFeature2
nbrComments
= swCommentFolder.GetCommentCount
Debug.Print
"Number of comments in Comments folder = "
& nbrComments
Debug.Print
""
vComments
= swCommentFolder.GetComments
For
i = 0 To (nbrComments - 1)
Set
swComment = vComments(i)
Debug.Print
"Name of comment in FeatureManager design tree = " & swComment.Name
Debug.Print
"Text of comment =
" & swComment.Text
Debug.Print
""
Next
i
End
If
'
Get next feature in FeatureManager design tree
Set
swFeat = swFeat.GetNextFeature
Loop
End Sub