ds-blue-logo
Preview  |  SOLIDWORKS USER FORUM
Use your SOLIDWORKS ID or 3DEXPERIENCE ID to log in.
FDFrédérik Drouin12/12/2017

I created a macro that create a note at a position in a drawing and then save this drawing as a PDF in the same folder, but now i want to delete this note after the save as PDF and i don't know how to delete it without selected it. Does anyone know how to do that ? Here is my code :

Dim swApp As Object

Dim Part As Object

Dim boolstatus As Boolean

Dim longstatus As Long, longwarnings As Long

Sub main()

Set swApp = Application.SldWorks

Set swModel = swApp.ActiveDoc

  

            If (swModel Is Nothing) Then

        MsgBox "No active file found in SolidWorks." & Chr(13) & Chr(13) _

            & "Please load/activate a SolidWorks Drawing and TRY again!", vbExclamation

            End

           End If

  

            If (swModel.GetType <> swDocDRAWING) Then

        MsgBox "Current file is not a SolidWorks Drawing." & Chr(13) & Chr(13) _

            & "Please Open/Activate a SolidWorks Drawing and TRY again!", vbExclamation

            End

           End If

Set Part = swApp.ActiveDoc

Dim myModelView As Object

Set myModelView = Part.ActiveView

myModelView.FrameState = swWindowState_e.swWindowMaximized

Dim myNote As Object

Dim myAnnotation As Object

Dim myTextFormat As Object

Set myNote = Part.InsertNote("$PRP:""SW-Short Date(Short Date)""   TYPE YOUR TEXT HERE")

If Not myNote Is Nothing Then

   myNote.LockPosition = False

   myNote.Angle = 0

   boolstatus = myNote.SetBalloon(0, 0)

   Set myAnnotation = myNote.GetAnnotation()

   If Not myAnnotation Is Nothing Then

      longstatus = myAnnotation.SetLeader3(swLeaderStyle_e.swNO_LEADER, 0, True, False, False, False)

      boolstatus = myAnnotation.SetPosition(1.18224818891099E-02, 7.61066835915902E-03, 0)

      boolstatus = myAnnotation.SetTextFormat(0, True, myTextFormat)

   End If

End If

Part.ClearSelection2 True

Part.WindowRedraw

Dim FilePath As String

Dim PathSize As Long

Dim PathNoExtention As String

Dim NewFilePath As String

FilePath = Part.GetPathName

PathSize = Strings.Len(FilePath)

PathNoExtention = Strings.Left(FilePath, PathSize - 6)

NewFilePath = PathNoExtention & "pdf"

Part.SaveAs2 NewFilePath, 0, True, False

End Sub