3 Replies Latest reply on Sep 7, 2018 7:27 AM by Kenneth Coutinho

    How to create a macro that inserts the current date (format:07SEP18) as a note in a drawing file?

    Kenneth Coutinho

      Hey guys,

       

      I'm just beginning to use macros to simplify my work.

      A note needs to be added on some prototype drawings which mentions the current date.

      I tried creating a macro by recording it and then trying to edit it but it was unsuccessful.

      Kindly advise.

       

      Sub main()

       

       

      Set swApp = Application.SldWorks

       

       

      Set Part = swApp.ActiveDoc

      boolstatus = Part.ActivateView("Drawing View3")

      boolstatus = Part.ActivateSheet("Sheet1")

      Part.FONTBOLD True

      Part.FontPoints 22

       

       

      Dim myNote As Object

      Dim myAnnotation As Object

      Dim myTextFormat As Object

       

       

      Set myNote = Part.InsertNote("<FONT color=0x000000ff><FONT size=22PTS style=B>FOR PROTO BUILD ONLY" + Chr(13) + Chr(10) + _

              "07SEP18")

      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(0.308895790590732, 0.339959288537549, 0)

       

       

            Set myTextFormat = Part.GetUserPreferenceTextFormat(0)

            myTextFormat.Italic = False

            myTextFormat.Underline = False

            myTextFormat.Strikeout = False

            myTextFormat.Bold = True

            myTextFormat.Escapement = 0

            myTextFormat.LineSpacing = 0.001

            myTextFormat.CharHeightInPts = True

            myTextFormat.TypeFaceName = "Arial Narrow"

            myTextFormat.WidthFactor = 1

            myTextFormat.ObliqueAngle = 0

            myTextFormat.LineLength = 0

            myTextFormat.Vertical = False

            myTextFormat.BackWards = False

            myTextFormat.UpsideDown = False

            myTextFormat.CharSpacingFactor = 1

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

         End If

      End If

      Part.ClearSelection2 True

      Part.WindowRedraw

      End Sub

        • Re: How to create a macro that inserts the current date (format:07SEP18) as a note in a drawing file?
          Kenneth Coutinho

          I got what I was looking for:

           

           

          Dim myNote As Object

          Dim myAnnotation As Object

          Dim myTextFormat As Object

           

           

           

          nowtext = Format(Now(), "DDMMMYY")

           

           

          Set myNote = Part.InsertNote("<FONT color=0x000000ff><FONT size=22PTS style=B>FOR PROTO BUILD ONLY" + Chr(13) + Chr(10) + _

                   nowtext)

          If Not myNote Is Nothing Then

             myNote.LockPosition = False

             myNote.Angle = 0

             boolstatus = myNote.SetBalloon(0, 0)

             myNote.SetTextJustification (swTextJustificationCenter)

             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(0.308895790590732, 0.339959288537549, 0)

           

           

                Set myTextFormat = Part.GetUserPreferenceTextFormat(0)

                myTextFormat.Italic = False

                myTextFormat.Underline = False

                myTextFormat.Strikeout = False

                myTextFormat.Bold = True

                myTextFormat.Escapement = 0

                myTextFormat.LineSpacing = 0.001

                myTextFormat.CharHeightInPts = True

                myTextFormat.TypeFaceName = "Arial Narrow"

                myTextFormat.WidthFactor = 1

                myTextFormat.ObliqueAngle = 0

                myTextFormat.LineLength = 0

                myTextFormat.Vertical = False

                myTextFormat.BackWards = False

                myTextFormat.UpsideDown = False

                myTextFormat.CharSpacingFactor = 1

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

             End If

          End If

          Part.ClearSelection2 True

          Part.WindowRedraw

          End Sub

          • Re: How to create a macro that inserts the current date (format:07SEP18) as a note in a drawing file?
            Fifi Riri

            You can simplify it as so:

             

            Option Explicit

            Sub main()

            Dim swapp As SldWorks.SldWorks

            Dim part As SldWorks.DrawingDoc

            Dim boolstatus As Boolean

            Set swapp = Application.SldWorks

            Set part = swapp.ActiveDoc

            Dim myNote As SldWorks.Note

            Dim myAnnotation As SldWorks.Annotation

            Set myNote = part.InsertNote("<FONT color=0x000000ff><FONT size=22PTS style=B>FOR PROTO BUILD ONLY" & vbCr & UCase(Format(Now, "DDMMMYY")))

            If Not myNote Is Nothing Then

               Set myAnnotation = myNote.GetAnnotation

               If Not myAnnotation Is Nothing Then

                  boolstatus = myAnnotation.SetPosition(0.3, 0.3, 0)

               End If

            End If

            part.ClearSelection2 True

            End Sub