4 Replies Latest reply on Aug 10, 2014 5:12 AM by Deepak Gupta

    InsertSketchText Method Text Size?

    Suraj Khosla

      I am trying to add text to a sketch in the part model document using the Solidworks API.

       

      Is there any way of adjusting the size of text using API for the InsertSketchText method? I can see a width scale factor but nothing for the height/overall text size.

        • Re: InsertSketchText Method Text Size?
          Suraj Khosla

          Currently using:

           

          Set mySketchText = Part.InsertSketchText(0, -0.003, 0, "*", 0, 0, 0, 100, 0)

           

          To insert my text but comes in as a set size, don't know how to adjust it. I have read that "<r65>*</r>" can be used to rotate the text, wonder if there is something like this for the size/font also.

            • Re: InsertSketchText Method Text Size?
              Deepak Gupta

              Check SetTextFormat method.

                • Re: InsertSketchText Method Text Size?
                  Suraj Khosla

                  Thanks for your reply, I cannot get this to work in the part document as for some reason solidworks doesnt seem to treat text in sketch's as an annotation, works fine in a drawing document just not in the part sketch.

                    • Re: InsertSketchText Method Text Size?
                      Deepak Gupta

                      Try this:

                       

                      Option Explicit

                      Sub main()

                          Dim swApp                   As SldWorks.SldWorks

                          Dim swModel                As SldWorks.ModelDoc2

                          Dim swSkText               As SldWorks.SketchText

                          Dim nTextFormat           As SldWorks.TextFormat

                       

                          Set swApp = Application.SldWorks

                          Set swModel = swApp.ActiveDoc

                         

                          Set nTextFormat = swModel.GetUserPreferenceTextFormat(SwConst.swDetailingNoteTextFormat)

                          nTextFormat.CharHeightInPts = 25 'Change height here

                             

                          Set swSkText = swModel.InsertSketchText(0#, 0#, 0#, "Test", 0, 0, 0, 100, 100) 'Change text here, replace Test with required text.

                          swSkText.SetTextFormat False, nTextFormat

                       

                      End Sub