Hi @GoldSA,
Please, try the following code:
(prompt "\nTo run a LISP type: COMTXT")
(princ)
(defun c:COMTXT ( / ent text_val text_val_ascii minPt maxPt ss len i new_txt output_txt sort_num n txt_val new_output_txt pt)
(setq ent (car (entsel "\nSelect TEXT:"))
text_val (cdr (assoc 1 (entget ent)))
text_val_ascii (ascii (substr text_val 1 1))
)
(vla-GetBoundingBox (vlax-ename->vla-object ent) 'minPt 'maxPt)
(setq minPt (vlax-safearray->list minPt)
maxPt (vlax-safearray->list maxPt)
)
(setq ss (ssget "_F" (list minPt maxPt) (list (cons 0 "*TEXT"))))
(if (ssmemb ent ss)
(ssdel ent ss)
)
(setq len (sslength ss)
i 0
new_txt (list (list text_val))
)
(while (< i len)
(setq txt_val (list (cdr (assoc 1 (entget (ssname ss i)))))
txt_val_ascii (ascii (substr (nth 0 txt_val) 1 1))
)
(cond
((< txt_val_ascii text_val_ascii)
(setq new_txt (append (list txt_val) new_txt))
)
((> txt_val_ascii text_val_ascii)
(setq new_txt (cons txt_val new_txt))
)
)
(setq i (1+ i))
)
(setq output_txt (mapcar (function (lambda (x) (car x))) new_txt)
sort_num (vl-sort-i output_txt '<)
n 0
)
(repeat (length output_txt)
(setq txt_val (nth (nth n sort_num) output_txt)
new_output_txt (append (list txt_val) new_output_txt)
n (1+ n)
)
)
(setq new_output_txt (reverse new_output_txt)
output_txt (apply 'strcat new_output_txt)
pt (getpoint "\nPick the point to insert a concatenated text:")
)
(entmake (list (cons 0 "TEXT") (cons 100 "AcDbEntity") (cons 100 "AcDbText") (cons 10 pt) (cons 40 (cdr (assoc 40 (entget ent)))) (cons 1 output_txt) (cons 50 (cdr (assoc 50 (entget ent))))))
(princ)
)
When I use the code from above, I get this (picture 1). ** On the first input values "A B C", they overlap each other, but have a different insertation point for the text entity.
Best regards.