Text length

Discussion in 'AutoCAD' started by stevej, Aug 11, 2003.

  1. stevej

    stevej Guest

    Hello all

    Is there any way of finding the length of a string of text?
    I'm writing a vla-only 'text to mtext routine' & would like to be able to set (vla-put-width) to the appropriate figure.
    I'll be using the routine via a reactor if it makes any difference.

    Thanks,

    Steve
     
    stevej, Aug 11, 2003
    #1
  2. stevej

    R.K. McSwain Guest

    Textbox Function: Measures a specified text object, and returns the diagonal coordinates of a box that encloses the text
     
    R.K. McSwain, Aug 11, 2003
    #2
  3. There may be an easier way, but I'd try:
    1. save existing justification
    2. use textjustify to set right justification
    3. get dxf codes 10 and 11
    4. restore original justification

    Code 10 should return the insertion point if the text was left
    justified, while code 11 should return the insertion point if the text
    was right justified. The length should be the distance between the two
    points.

    Martin
     
    Martin Shoemaker, Aug 11, 2003
    #3
  4. stevej

    Devin Guest

    (defun text_len ( arg_txt / box )
      (setq
        box
         (textbox
           (list
             (cons 1 arg_txt)
             (cons 40 (ed_con 0.1))
             (cons 41 0.8)
           )
         )
      )
      (abs (- (x (car box)) (x (cadr box))))
    )
     
    Devin, Aug 11, 2003
    #4
  5. stevej

    Devin Guest

    Excuse me for the internal functions.  Here's an adjustment that should work...



     



    (defun text_len ( arg_txt arg_ht arg_wd / box )
      (setq
        box
         (textbox
           (list
             (cons 1 arg_txt);text
             (cons 40 arg_ht);text height 
             (cons 41 arg_wd);text width factor
           )
         )
      )
      (abs (- (car (car box)) (car (cadr box))))
    )



     





    HTH,



     



    Devin
     
    Devin, Aug 11, 2003
    #5
  6. (textbox) is not the most reliable function to use with mtext.

    Given 2 pieces of text "AB", one string has a height equal
    to the height defined in the style (3/32") the other has an
    overridden height of 1".

    Command: (textbox (list (assoc 1 (entget (car (entsel))))))

    Select object: ((0.0 0.0 0.0) (0.160714 0.09375 0.0))

    Command: (textbox (list (assoc 1 (entget (car (entsel))))))

    Select object: ((0.0 0.0 0.0) (0.160714 0.09375 0.0))
     
    Jason Piercey, Aug 11, 2003
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.