ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
KTKevin Thompson28/11/2018

I'm trying to write a macro that will insert a comment into the feature tree and then rename the "Comments" folder followed by renaming the newly inserted comment in the feature tree.  I've been successful in writing code to insert the comment and rename the "Comments" folder, however, I've been unsuccessful in renaming the newly inserted comment in the feature tree.  I've got some decent vb experience in Excel macros, but virtually no experience with SolidWorks macros so i'm a bit lost on what to do next.  Any help would be appreciated!  The code that I've tried follows:

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

Dim feature As SldWorks.feature

Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = _

Application.SldWorks

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

Dim myComment As Object

Set myComment = Part.Extension.AddComment("TEST")

boolstatus = Part.Extension.SelectByID2("Comments", "COMMENTSFOLDER", 0, 0, 0, False, 0, Nothing, 0)

Set feature = Part.SelectionManager.GetSelectedObject6(1, 0)

feature.Name = "Comments Folder Name"

boolstatus = Part.Extension.SelectByID2("Comment1", "COMMENT", 0, 0, 0, False, 0, Nothing, 0)

Set feature = Part.SelectionManager.GetSelectedObject6(1, 0)

feature.Name = "Comment Feature Name"

End Sub

The comment gets inserted and the folder name gets updated to "Comments Folder Name" when i'm in break mode and run it with a break at the second 'feature.Name' command.  But when i run past the break and try to select the "Comment1" feature and change it's name, it changes the folder name again to what I want the comment feature name to be instead.  Any suggestions?