;;; Draw bounding box around texts, mtexts and attributes in a same layer as selected entities
;;; Created by Igal Averbuh 2017 (Inspired by Msasu routine)
;;; Saved from here: http://www.cadtutor.net/forum/showthread.php?89942-Automate-to-create-bounding-box-for-all-text-objects

(defun c:TB ( / suffixLayer ss nameEnt assocEnt nameLayer )
(if (not bns_tcircle) (load "acettxt.lsp"))

(if (setq ss (ssget '((0 . "TEXT,MTEXT,ATTDEF")))) ;select all labels from drawing

(while (> (sslength ss) 0) ;parse selection set until empty
(setq nameEnt (ssname ss 0) ;retrive first entry from selection set
assocEnt (entget nameEnt))

(setq nameLayer (strcat (cdr (assoc 8 assocEnt))))
(command "_LAYER" "_S" nameLayer "")
; )

(bns_tcircle (ssadd nameEnt) "Variable" "Rectangles" "" 0.35) ;add the bounding box

(setq ss (ssdel nameEnt ss)) ;remove processed entry from selection set
)

)
(princ)
)
(c:TB)