Text length

stevej

Usenet Archive
Joined
Nov 4, 2000
Messages
15
Reaction score
0
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 said:
Hello all
Is there any way of finding the length of a string of text?

Textbox Function: Measures a specified text object, and returns the diagonal coordinates of a box that encloses the text
 
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
 
(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))))
)
 
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
 
(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))
 

Latest threads

Back
Top