18 Replies Latest reply on May 6, 2016 7:13 AM by Matt Petersen

    Watermark on all sheets centered on sheet

    jason kooken

      I need to make a macro that can add "for quote only" on all sheets of a drawing.

      I have not added text to a drawing before using API so any help would be greatly appreciated.

       

      it needs to be:

      behind drawing views

      on all sheets

      at a 30 degree angle

      centered to different size sheets

      thanks in advance.

        • Re: Watermark on all sheets centered on sheet
          John Stoltzfus

          An easy way to do this is make a new template and edit the sheet and add a note, change the color of the text to give it the watermark look that you need

           

          • Re: Watermark on all sheets centered on sheet
            Deepak Gupta

            I would add a custom property in the drawing file properties with required text. Then simply add a note on drawing sheet and link to this property.

             

            Now simply copy paste on all sheets. And when you don't need the watermark, simply remove the property text and it will puff off

            • Re: Watermark on all sheets centered on sheet
              jason kooken

              Unfortunately, this is to be applied to existing drawings and I need it to be a one button sort of thing, so adding a property or new sheet templates wont work, using a macro is key.

                • Re: Watermark on all sheets centered on sheet
                  Michael Spens

                  Hi Jason,

                  This process records well with the macro recorder.  Try the following. Linking to a property is certainly a good idea for future watermark modification.  (edited from first post with sheet centering)

                   

                  Set swApp = _

                  Application.SldWorks

                   

                  Set Part = swApp.ActiveDoc

                  Dim draw As DrawingDoc

                  Set draw = Part

                  Dim sht As Sheet

                  Set sht = draw.GetCurrentSheet

                  Dim shtProps As Variant

                  shtProps = sht.GetProperties2

                  Dim width As Double

                  width = shtProps(5)

                  Dim height As Double

                  height = shtProps(6)

                   

                  Part.EditTemplate

                  Part.EditSketch

                   

                  Dim myNote As Note

                  Dim myAnnotation As Annotation

                  Dim myTextFormat As TextFormat

                  Set myNote = Part.InsertNote("WATERMARK")

                  If Not myNote Is Nothing Then

                     myNote.BehindSheet = True

                     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(width / 2, height / 2, 0)

                        myAnnotation.Color = 12632256

                        Set myTextFormat = Part.GetUserPreferenceTextFormat(0)

                        myTextFormat.Bold = True

                        myTextFormat.CharHeight = 0.04

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

                     End If

                  End If

                   

                   

                  Part.EditTemplate

                  Part.EditSheet

                  • Re: Watermark on all sheets centered on sheet
                    John Stoltzfus

                    I didn't explain my workflow here....

                     

                    All my custom properties are in either the parts or assembly level and are treated individually, not an overall.  I also use multiple drawing pages which include the assembly files and all the part files for that assembly.  If we have an ECR or ECN design change, we don't want the watermark being printed on every page if it's not needed, just the parts that are changing or for review only etc..... 

                     

                    Use whatever works for you

                  • Re: Watermark on all sheets centered on sheet
                    Kevin Chisholm

                    Are you using SW2016?

                     

                    I'm asking because you could use this:

                    2016 SOLIDWORKS API Help - WatermarkNote Property (INote)

                    • Re: Watermark on all sheets centered on sheet
                      jason kooken

                      Ok, so this is what I have so far, I was not able to establish the center of the sheet like above, also I need this to run on all sheets

                       

                      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 Part = swApp.ActiveDoc

                      boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0.3, 0.1, 0, False, 0, Nothing, 0)

                      Part.EditTemplate

                      Part.EditSketch

                      Part.ClearSelection2 True

                       

                      Dim myNote As Object

                      Dim myAnnotation As Object

                      Dim myTextFormat As Object

                      Set myNote = Part.InsertNote("<FONT color=0x00808080>FOR QUOTE ONLY")

                      If Not myNote Is Nothing Then

                         myNote.LockPosition = False

                         myNote.Angle = 0.5235987755983

                         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.2, 0.2, 0)

                       

                            Set myTextFormat = Part.GetUserPreferenceTextFormat(0)

                            myTextFormat.Italic = False

                            myTextFormat.Underline = False

                            myTextFormat.Strikeout = False

                            myTextFormat.Bold = False

                            myTextFormat.Escapement = 0.5235987755983

                            myTextFormat.LineSpacing = 0.001

                            myTextFormat.CharHeight = 0.0254

                            myTextFormat.TypeFaceName = "Century Gothic"

                            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.EditSheet

                      Part.ClearSelection2 True

                      End Sub

                        • Re: Watermark on all sheets centered on sheet
                          Michael Spens

                          Hi Jason,

                          To make it work with all drawing sheets, surround this whole mess in a loop that goes through each.  And for 2014, use GetProperties like the following.  GetProperties2 is only in 2016.

                          ...

                          Dim draw As DrawingDoc

                          Set draw = Part

                          Dim sht As Sheet

                          Dim shNames As Variant

                          sheetNames = draw.GetSheetNames

                          Dim sheetName As Variant

                           

                          For Each sheetName In sheetNames

                              'get sheet size info

                              draw.ActivateSheet (sheetName)

                              Set sht = draw.GetCurrentSheet

                              Dim shtProps As Variant

                              shtProps = sht.GetProperties

                              Dim width As Double

                              Dim height As Double

                              width = shtProps(5)

                              height = shtProps(6)

                           

                              ... your code here...

                           

                              Part.EditTemplate

                              Part.EditSheet

                             

                          Next sheetName

                           

                          End Sub

                           

                           

                          Use the height and width variable values in your note position...

                          boolstatus = myAnnotation.SetPosition(width / 2, height / 2, 0)

                          You could even take half of your font height and add it to the Y value of SetPosition if needed.

                        • Re: Watermark on all sheets centered on sheet
                          Viktor Bovzdarenko

                          Hi Jason

                          With #TASK  library macro I was able to add such notes in butch mode for hundreds of drawings.

                          Here is the example:

                          And here are the setting which I used for A3 format (in mm and degrees for my drawings. You should use your document units for length)

                          Choose 2 macro from the library: "Insert Annotation" and "Annotation Formatting"

                          "Insert Annotation" settings:

                          "Annotation Formatting"

                           

                          However, this annotation is added as usual annotation and it is not behind all views.

                          Also, this annotation could be later deleted or edited by #TASK

                          Hope this helps

                          Regards

                          Viktor

                          • Re: Watermark on all sheets centered on sheet
                            jason kooken

                            So I havent been able to get the above to work, and I cant use the above drawing text as the requirement was for it to be on the format.

                             

                            I have chosen a different route I have identified the three different locations for the text on each of our sheet templates. What I want the below to say is:

                             

                            if sheet template is "B SIZE SHEET1 2015" then  myAnnotation.SetPosition(0.25, 0.25, 0)

                            if sheet template is "C SIZE SHEET1 2015"  then  myAnnotation.SetPosition(0.15, 0.15, 0)

                            I have been struggling with this for a few days now, apparently I am not very good at it. If someone can just edit below to make this work hat would be awesome.

                             

                             

                             

                             

                            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 Part = swApp.ActiveDoc

                            boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0.3, 0.1, 0, False, 0, Nothing, 0)

                            Part.EditTemplate

                            Part.EditSketch

                            Part.ClearSelection2 True

                            Dim myNote As Object

                            Dim myAnnotation As Object

                            Dim myTextFormat As Object

                            Set myNote = Part.InsertNote("<FONT color=0x00808080>FOR QUOTE ONLY")

                            If Not myNote Is Nothing Then

                            myNote.LockPosition = False

                            myNote.Angle = 0.5235987755983

                            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)

                                

                             

                            'location

                            boolstatus = myAnnotation.SetPosition(0.25, 0.2, 0)

                             

                             

                            'font info

                                  Set myTextFormat = Part.GetUserPreferenceTextFormat(0)

                                  myTextFormat.Italic = False

                                  myTextFormat.Underline = False

                                  myTextFormat.Strikeout = False

                                  myTextFormat.Bold = False

                                  myTextFormat.Escapement = 0.5235987755983

                                  myTextFormat.LineSpacing = 0.001

                                  myTextFormat.CharHeight = 0.0254

                                  myTextFormat.TypeFaceName = "Swis721 BlkOul BT"

                                  myTextFormat.WidthFactor = 1.5

                                  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.EditSheet

                            Part.ClearSelection2 True

                            End Sub

                              • Re: Watermark on all sheets centered on sheet
                                Michael Spens

                                Hi Jason,

                                It wasn't clear what wasn't working for you, but here's an example of plugging your code into the previous, traversing each sheet.  One missing bit was to get the sheet size from GetProperties and use that to set the text location.  You may still need to adjust positions.  Hope it helps!

                                 

                                '================================================

                                Dim swApp As SldWorks.SldWorks

                                Dim Part As ModelDoc2

                                Dim boolstatus As Boolean

                                Dim longstatus As Long, longwarnings As Long

                                 

                                 

                                Sub main()

                                    Set swApp = _

                                        Application.SldWorks

                                    Set Part = swApp.ActiveDoc

                                   

                                    Dim draw As DrawingDoc

                                    Set draw = Part

                                    Dim sht As Sheet

                                    Dim shNames As Variant

                                    sheetNames = draw.GetSheetNames

                                    Dim sheetName As Variant

                                    

                                    For Each sheetName In sheetNames

                                        'get sheet size info

                                        draw.ActivateSheet (sheetName)

                                        Set sht = draw.GetCurrentSheet

                                        Dim shtProps As Variant

                                        shtProps = sht.GetProperties

                                        Dim width As Double

                                        Dim height As Double

                                        Dim shtSize As Long

                                        shtSize = shtProps(0)

                                        width = shtProps(5)

                                        height = shtProps(6)

                                    

                                        '... your code here...

                                       

                                        'boolstatus = Part.Extension.SelectByID2("Sheet1", "SHEET", 0.3, 0.1, 0, False, 0, Nothing, 0)

                                        draw.EditTemplate

                                        draw.EditSketch

                                        Part.ClearSelection2 True

                                        Dim myNote As Object

                                        Dim myAnnotation As Object

                                        Dim myTextFormat As Object

                                        Set myNote = Part.InsertNote("<FONT color=0x00808080>FOR QUOTE ONLY")

                                        If Not myNote Is Nothing Then

                                        myNote.LockPosition = False

                                        myNote.Angle = 0.5235987755983

                                        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)

                                                

                                            

                                            'location - edited for sheet size

                                            Select Case shtSize

                                                Case swDwgPaperCsize

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

                                                Case swDwgPaperBsize

                                                    boolstatus = myAnnotation.SetPosition(0.25, 0.2, 0)

                                            End Select

                                                

                                            

                                            'font info

                                              Set myTextFormat = Part.GetUserPreferenceTextFormat(0)

                                              myTextFormat.Italic = False

                                              myTextFormat.Underline = False

                                              myTextFormat.Strikeout = False

                                              myTextFormat.Bold = False

                                              myTextFormat.Escapement = 0.5235987755983

                                              myTextFormat.LineSpacing = 0.001

                                              myTextFormat.CharHeight = 0.0254

                                              myTextFormat.TypeFaceName = "Swis721 BlkOul BT"

                                              myTextFormat.WidthFactor = 1.5

                                              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.EditSheet

                                        Part.ClearSelection2 True

                                        '... end of your code...

                                    

                                        Part.EditTemplate

                                        Part.EditSheet

                                      

                                    Next sheetName

                                       

                                       

                                End Sub

                              • Re: Watermark on all sheets centered on sheet
                                Randy Palmer

                                I just today had to add a watermark to a drawing.  Easiest way was to edit the sheet format, add the note, and in the text properties select "behind sheet".  I made the text a color that looked watermarky.  It would seem like this would be an easy macro to record and run for each drawing.  This puts the note behind the views.

                                • Re: Watermark on all sheets centered on sheet
                                  jason kooken

                                  Thank you all for your help and patients! I am all set now.