Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/30/2025 in all areas

  1. My effort... Just Text... ;;; Combine different overlapping text alphabetically. ;;; ;;; https://www.cadtutor.net/forum/topic/98013-is-it-possible-for-combining-different-texts-that-overlapping/#findComment-671805 ;;; ;;; By SLW210 (a.k.a. Steve Wilson) ;;; (defun c:CombTxtABC ( / ss i ent txts sorted-text result-text base-point) ;; Get string value (defun get-text-entity (ent) (cdr (assoc 1 (entget ent))) ) ;; Get insertion point (defun get-ins-point (ent) (cdr (assoc 10 (entget ent))) ) ;; Sort alphabetically (defun sort-by-text (a b) (if (equal (cadr a) (cadr b)) nil (if (or (null (cadr a)) (null (cadr b))) (null (cadr a)) (< (cadr a) (cadr b)) ) ) ) ;; Prompt user (setq ss (ssget '((0 . "TEXT")))) ; Only allow TEXT (not MTEXT) (if ss (progn (setq txts '()) ;; Loop through (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (if (and ent (eq (cdr (assoc 0 (entget ent))) "TEXT")) (setq txts (cons (list (get-ins-point ent) (get-text-entity ent) ent) txts)) ) (setq i (1+ i)) ) ;; Sort by content (setq sorted-text (vl-sort txts 'sort-by-text)) ;; Combine all (setq result-text "") (foreach text-item sorted-text (setq result-text (strcat result-text (cadr text-item))) ) ;; Insertion point from first text (setq base-point (car (car sorted-text))) ;; Create new TEXT with combined string (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer (cons 10 base-point) (cons 40 1.0) ; Height (cons 1 result-text) (cons 7 "Standard") ; Text style (cons 72 1) ; Center justified (cons 11 base-point) ) ) ;; Delete original text (foreach text-item sorted-text (if (and (listp text-item) (cdr (assoc 0 (entget (caddr text-item))))) (entdel (caddr text-item)) ) ) (princ (strcat "\nCombined text: " result-text)) ) (princ "\nNo valid TEXT selected.") ) (princ) ) Text/MText... ;;; Combine different overlapping text/Mtext alphabetically. ;;; ;;; https://www.cadtutor.net/forum/topic/98013-is-it-possible-for-combining-different-texts-that-overlapping/#findComment-671805 ;;; ;;; By SLW210 (a.k.a. Steve Wilson) ;;; (defun c:CombTxt_MTxtABC ( / ss i ent txts sorted-text result-text base-point) ;; Get string value (defun get-text-entity (ent) (if (eq (cdr (assoc 0 (entget ent))) "MTEXT") (cdr (assoc 1 (entget ent))) ; For MTEXT (cdr (assoc 1 (entget ent))) ; For TEXT ) ) ;; Get insertion point (defun get-ins-point (ent) (cdr (assoc 10 (entget ent))) ) ;; Sort alphabetically (defun sort-by-text (a b) (if (equal (cadr a) (cadr b)) nil (if (or (null (cadr a)) (null (cadr b))) (null (cadr a)) (< (cadr a) (cadr b)) ) ) ) ;; Prompt user (setq ss (ssget '((0 . "TEXT,MTEXT")))) ; Allow both TEXT and MTEXT (if ss (progn (setq txts '()) ;; Loop through (setq i 0) (while (< i (sslength ss)) (setq ent (ssname ss i)) (if (and ent (or (eq (cdr (assoc 0 (entget ent))) "TEXT") (eq (cdr (assoc 0 (entget ent))) "MTEXT"))) (setq txts (cons (list (get-ins-point ent) (get-text-entity ent) ent) txts)) ) (setq i (1+ i)) ) ;; Sort by content (setq sorted-text (vl-sort txts 'sort-by-text)) ;; Combine all (setq result-text "") (foreach text-item sorted-text (setq result-text (strcat result-text (cadr text-item))) ) ;; Insertion point from first text (setq base-point (car (car sorted-text))) ;; Create new text with combined string (entmake (list (cons 0 "TEXT") (cons 8 "0") ; Layer (cons 10 base-point) (cons 40 1.0) ; Height (cons 1 result-text) (cons 7 "Standard") ; Text style (cons 72 1) ; Center justified (cons 11 base-point) ) ) ;; Delete original (foreach text-item sorted-text (if (and (listp text-item) (cdr (assoc 0 (entget (caddr text-item))))) (entdel (caddr text-item)) ) ) (princ (strcat "\nCombined (M)Text: " result-text)) ) (princ "\nNo valid Text or MText entities selected.") ) (princ) )
    3 points
  2. Hi The easiest way is to explode up the text. You can add at the end (vla-explode (vlax-ename->vla-object (setq eu (entlast)))) (entdel eu)
    3 points
  3. 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.
    2 points
  4. Another option, more respectful of the original format, could be to replace your Entmakex with this one. (entmakex (foreach as el (setq l (if (setq v (cond ((= (setq c (car as)) 0) '(0 . "TEXT")) ((member c '(8 1 40 50 7 72)) as) ((= c 71) (cons c (cadr (assoc (cdr as) '((1 2) (2 1) (3 0) (4 0) (5 0)))))) ((= c 73) '(73 . 2)) ((member c '(10 11)) (cons c p2)) ) ) (append l (list v)) l ) ) ) )
    2 points
  5. 1 point
  6. If you decide on the second option, do not forget to include in the list of local variables, after (defun c:EXC (/ the new entmakex variables: as l c v
    1 point
  7. I have moved your thread to the The CUI, Hatches, Linetypes, Scripts & Macros Forum.
    1 point
  8. 1 point
×
×
  • Create New...