AnsweredAssumed Answered

Help with sldworks.comment API

Question asked by Eric Schwieterman on Jan 9, 2019
Latest reply on Jan 10, 2019 by Rob Edwards

I have code that is looping through the design tree in an assembly and I am looking for a way to mark or flag components that I want to delete at the end of the macro.

I am trying to mark the component with a comment and then loop back through the tree and find the components with the comment, select them and delete them.


Here is a simple piece of code for an example.  I get stuck when setting the comment.  I have everything working to create the comment.  I just need help finding the comment in the component.


Dim swApp                    As SldWorks.SldWorks

Dim swAssy                   As SldWorks.IAssemblyDoc

Dim swPart                   As SldWorks.PartDoc

Dim swDraw                   As SldWorks.DrawingDoc

Dim boolstatus               As Boolean

Dim longstatus               As Long, longwarnings As Long

Dim swModel                  As SldWorks.ModelDoc2

Dim fileerror                As Long

Dim filewarning              As Long

Dim swFeatMgr                As SldWorks.FeatureManager

Dim swSelMgr                 As SldWorks.SelectionMgr

Dim nErrors                  As Long

Dim nWarnings                As Long

Dim swTableAnn               As SldWorks.TableAnnotation

Dim swView                   As SldWorks.View

Dim swCustPropMgr            As SldWorks.CustomPropertyManager

Dim swConfMgr                As SldWorks.ConfigurationManager

Dim SwConfig                 As SldWorks.Configuration

Dim swModelDocExt            As SldWorks.ModelDocExtension

Dim swMate                   As Mate2

Dim swComp                   As SldWorks.Component2

Dim vComps                   As Variant

Dim exttype                  As String

Dim swFeat                  As SldWorks.Feature

Dim swprevFeat               As SldWorks.Feature

Sub main()



    Set swApp = GetObject(, "SldWorks.Application")



Set swAssy = swApp.ActiveDoc

    swComponents = swAssy.GetComponents(True)

    Set swModel = swApp.ActiveDoc

    Set swFeatMgr = swModel.FeatureManager

    Set swFeat = swModel.FirstFeature

    Set swModel = swApp.ActiveDoc


  Do Until swFeat.GetTypeName = "Reference"

    Set swFeat = swFeat.GetNextFeature



        Debug.Print swFeat.Name

        Debug.Print swFeat.GetTypeName



        swFeat.Select (False)

        swFeat.AddComment ("delete")




Dim swComment As SldWorks.Comment

Dim CommentName As String

Set swSelMgr = swModel.SelectionManager

Set swComp = swSelMgr.GetSelectedObjectsComponent2(1)

Debug.Print swComp.Name



Set swComment = swComp.swSelMgr.GetSelectedObject6





CommentName = swComment.text


        If CommentName <> "" Then


        End If





End Sub