Add Comment to Assembly Component Example (VBA)
This example shows how to add a comment to an assembly comment.
'------------------------------------------------
' Preconditions: Assembly document is open and a component
is selected.
'
' Postconditions: A comment is added to the selected component.
'------------------------------------------------
Option Explicit
Dim swApp As SldWorks.SldWorks
Dim swModel As SldWorks.ModelDoc2
Dim swSelMgr As SldWorks.SelectionMgr
Dim swModelDocExt As SldWorks.ModelDocExtension
Sub main()
Set swApp = Application.SldWorks
Set swModel = swApp.ActiveDoc
Set swSelMgr = swModel.SelectionManager
Set swModelDocExt = swModel.Extension
Dim selComp As SldWorks.Component2
Dim selCompName As String
Set selComp = swSelMgr.GetSelectedObjectsComponent3(1,
-1)
selCompName = selComp.Name2
Dim newComment As Object
Set newComment = swModelDocExt.AddComment("This
component's name is " & selCompName)
End Sub