3 Replies Latest reply on Oct 23, 2013 12:28 PM by Simon Turner

    Failed to rotate Text by 90 degs

    Hoang Nguyen


      I use a macro to insert a Time Stamp on a drawing.  I set the Angle property to 90 instead of the default 0.  It initially has it at the desired angle, but quickly flashes (resketch?) and the Time Stamp gets back to the horizontal orientation.  Please help.  Below is the code:




      ' --------------------------------------------------------------------2/17/2009

      ' Time and Date Stamp

      ' Time Stamp.swp

      ' This macro is provided as is.  No claims, support, refund, safety net, or

      ' warranties are expressed or implied.  By using this macro and/or its code in

      ' any way whatsoever, the user and any entities which the user represents,

      ' agree to hold the authors free of any and all liability.  Free distribution

      ' and use of this code in other free works is welcome.  If any portion of

      ' this code is used in other works, credit to the authors must be placed in

      ' that work within a user viewable location (e.g., macro header).  All other

      ' forms of distribution (i.e., not free, fee for delivery, etc) are prohibited

      ' without the expressed written consent by the authors.  Use at your own risk!


      ' Distributed by: http://sw.fcsuper.com

      ' ------------------------------------------------------------------------------

      ' Description:

      ' Allows the user to stamp the time and date on a drawing.

      ' Precondition before running macro:

      ' A preselected point on the drawing.

      ' ------------------------------------------------------------------------------

      ' Original Written by: Matthew Lorono Copyright 2006 (http://sw.fcsuper.com) with

      ' the a little help from Wasay Noori of Hawkridge Systems (www.hawkridgesys.com)

      ' Modification: Add pass thru so print function can be used for all documentn types;

      ' modified per input by Handleman http://www.eng-tips.com/viewthread.cfm?qid=174155.

      ' Modified by: Deepak Gupta (http://gupta9665.wordpress.com/). Added codes for adding

      ' the Custom Info & Note in the drawing. Option to set the position of Note (i.e., Pick Point

      ' in the drawing).

      ' ------------------------------------------------------------------------------





      Sub main()



      Dim swApp       As SldWorks.SldWorks



      Dim swModel     As Object



      Dim retval      As String



      Dim boolstatus As Boolean



      Dim longstatus As Long, longwarnings As Long



      'Dim PickPt     As Variant

      Dim PickPt(3)  As Double

          PickPt(0) = 0.025  'x

          PickPt(1) = 0.008   'y

          PickPt(2) = 1  'z   'must not be 0 or it won't show



      Dim bret As String


      Set swApp = Application.SldWorks



      Set swModel = swApp.ActiveDoc





      ' Error handler for no document loaded

        If swModel Is Nothing Then MsgBox "No document loaded!", vbCritical: End



        ' Error handler for document not being a drawing

        If swModel.GetType = 3 Then


      retval = swModel.AddCustomInfo3("", "Print Time", swCustomInfoText, "")



      'PickPt = swModel.GetInsertionPoint   ' Get user selected point



            If IsEmpty(PickPt) Then        ' Valid point?

              MsgBox "Please pick an insertion point before running macro.", _

                     vbExclamation: End    ' Add End statement to kill macro if precondition not met

      End If



      Dim myNote As Object

      Dim myAnnotation As Object

      Dim myTextFormat As Object

      Set myNote = swModel.InsertNote("$PRP:""Print Time""")

      If Not myNote Is Nothing Then

         myNote.Angle = 0

         boolstatus = myNote.SetBalloon(0, 0)

         Set myAnnotation = myNote.GetAnnotation()

         If Not myAnnotation Is Nothing Then

            longstatus = myAnnotation.SetLeader2(False, 0, True, True, False, False)

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

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

         End If

      End If



          ' Assign the current time and date to custom property

          retval = swModel.DeleteCustomInfo("Print Time")

          retval = swModel.AddCustomInfo("Print Time", "Text", Now)


          ' Refresh drawing display to show updated time and date

          retval = swModel.ForceRebuild3(False)




      ' Print the file. Remove ' from the below line to print the file

      ' retval = swModel.PrintOut2(0, 0, 1, False, 0, 0, False, 0)



        End If



      End Sub