Nikon, I'd consider adding a check that a suitable text was selected, quick and dirty like this:
;;Loop till a mtext is selected.
(while (not (equal (assoc 0 (entget (setq MyEnt (car (entsel "Select Mtext"))))) '(0 . "MTEXT") ))
(princ "\nNo, Please ")
)
Though of course if no mtext can be selected or the user changes their mind escape is the only way out so be wary of variables and error functions if needed.
If the text strings are always short (under 250 characters) your code can be shortened to something like this I think. The second ssget you can use a wildcard "*TEXT" to get all text types.
(defun c:test ( / )
;;Loop till a mtext is selected.
(while (not (equal (assoc 0 (entget (setq MyEnt (car (entsel "Select Mtext"))))) '(0 . "MTEXT") ))
(princ "\nNo, Please ")
)
;;get text string. Assuming the search text is less than 250 characters else use another method
(setq MyText (cdr (assoc 1 (entget myent))))
;;get a selection set. Again assuming text strings less then 250 characters.
(princ "\nNow select texts to search: ")
(setq MySS (ssget (list (cons 0 "MTEXT")(cons 1 (strcat "*" MyText "*")))))
;; do what you want here with MySS
(princ)
)
a slight different take on yours for longer texts which should work for LT too
(defun c:test ( / MyText MySS FinalSS acount)
;;Loop till a mtext is selected.
(while (not (equal (assoc 0 (entget (setq MyEnt (car (entsel "Select Mtext"))))) '(0 . "MTEXT") ))
(princ "\nNo, Please ")
)
(setq MyText (cdr (assoc 1 (entget myent)))) ;; selected text string
;;Get the texts to search.
(princ "\nNow select texts: ")
(setq MySS (ssget (list (cons 0 "*TEXT"))))
;; Loop through texts adding to selection set where text is found
(setq acount 0)
(setq FinalSS (ssadd))
(while (< acount (sslength MySS))
(setq MyEnt (entget (ssname MySS acount)))
(if (or
(wcmatch (strcase (cdr (assoc 1 MyEnt))) (strcat "*" (strcase Mytext) "*" )) ;; last 250 characters
(if (cdr (assoc 3 MyEnt))(progn
(wcmatch (strcase (cdr (assoc 3 MyEnt))) (strcat "*" (strcase Mytext) "*" )) ;; first 250 characers
(wcmatch (strcase (cdr (assoc 3 MyEnt))) (strcat "*" (strcase Mytext) "*" )) ;; Middle 250 characters
)) ; end if, end progn assoc 3
) ; endor
(progn ;; found
(setq FinalSS (ssadd (ssname MySS acount) FinalSS) )
)
(progn ;; not found
)
) ; end if
(setq acount (+ acount 1))
) ; end while
;; do what you want here with found texts
FinalSS
)