1 Reply Latest reply on Dec 5, 2016 7:54 PM by Shane Plohl

    How to obtain system time, date and user for note in SW drawing

    Shane Plohl

      Hi,

      Firstly, these forums have been a great help, and I thank everyone that contributes to them.

       

      I am currently trying to update a macro which saves a pdf of the drawing, to include a small bit of text which time and date stamps the pdf. Although I don't expect we'll use this bit of data much, I know from previous experience that it can be useful should we have any errors in our drawing management process.

       

      Is there a way to read and use the systems data and time in a solidworks macro?

       

      The way I see the macro working:

       

      User presses macro button,

      does some checks for open file etc

      save drawing file (if possible)

      adds stamp which will contain the time (hhmmss), date (YYMMDD), and the user (Name) - Example 101643161206SHANEP (I wanted the part/assembly PDM version, and drawing version here as well, but we need PDM pro for that…)

      Saves PDF in location specified by the ECN

      Deletes stamp

      Macro ends

       

      I am having a lot of difficulty finding how to obtain the system time in a solidworks macro. Previous threads on this forum have suggested using SW-Last Saved Date, and SW-Last saved by… This will work, just not if drawing is in an Approved state in PDM – as it will just capture the last time it was saved.

      Although the management process I am working on should stop this happening… I have no doubt it’ll happen, and I want to capture that information when it does happen.

       

      Another way I had thought of getting the information was to have the macro open an excel sheet, excel gets the time and date stamp using a macro, copies the data out, then somehow feeds it back into the macro… but I can’t get that to work either.

       

      As asked above, is there any way to read and use the system date and time in a solidworks macro? Like want can be done in  excel? Such as

       

      NowText = Format(Now(), "hhmmssyymmdd")

       

      Any help is greatly appreciated.

      Kind Regards,

      Shane

        • Re: How to obtain system time, date and user for note in SW drawing
          Shane Plohl

          Hi Everyone,

          Turns out i just had a simple syntax error and i'm now using the following and it works.

           

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

          user = Environ$("UserName")

          stamp = nowtext & user

          Set myNote = Part.InsertNote(stamp)

              If Not myNote Is Nothing Then

                 myNote.LockPosition = True

                 myNote.angle = 0

                 Set myAnnotation = myNote.GetAnnotation()

                 myNote.SetTextJustification (swTextJustificationRight)

                  If Not myAnnotation Is Nothing Then

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

                     boolstatus = myAnnotation.SetPosition(PointCoords(0), PointCoords(1), PointCoords(2))

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

                  End If

              End If