select similar the text or mtext that contain the same content ..

select similar the text or mtext that contain the same content ..

S_S_SS
Advocate Advocate
828 Views
7 Replies
Message 1 of 8

select similar the text or mtext that contain the same content ..

S_S_SS
Advocate
Advocate

Hello everyone
I need a lisp that select similar the text or mtext that contain the same content 

by selecting the text or mtext and press "st" then it select all the text or mtext that contain the same content

thanks in advance 

0 Likes
Accepted solutions (1)
829 Views
7 Replies
Replies (7)
Message 2 of 8

Kent1Cooper
Consultant
Consultant

Would Mtext always be "plain," without internal formatting?  If so, this would not be difficult.

Kent Cooper, AIA
Message 3 of 8

JBerns
Advisor
Advisor

Before going to LISP, have you tried the QSELECT or FILTER commands?

-----------------------------------------------------------------------------------------
CAD Administrator
Using AutoCAD & Inventor 2025
Autodesk Certified Instructor
Autodesk Inventor 2020 Certified Professional
Autodesk AutoCAD 2017 Certified Professional
Message 4 of 8

john.uhden
Mentor
Mentor

@S_S_SS ,

How about just using the FIND command?

John F. Uhden

Message 5 of 8

Kent1Cooper
Consultant
Consultant
Accepted solution

@S_S_SS wrote:

.... by selecting the text or mtext and press "st" then it select all the text or mtext that contain the same content ....


The QSELECT, FILTER and FIND suggestions ignore that part, and require you to feed in the content*, rather than getting it from an object you select.  Try this [lightly tested]:

 

(defun C:ST (/ tss tsel tdata); = Select Text [with same contents]
  (if
    (or
      (and
        (setq tss (ssget "_I" '((0 . "*TEXT")))); [M]Text among pre-selection
        (= (sslength tss) 1); only one
        (setq tdata (entget (ssname tss 0)))
      ); and
      (and
        (not (sssetfirst)); clear pre-selection if any
        (setq tsel (entsel "\nSelect [M]Text to find all with the same contents: "))
        (setq tdata (entget (car tsel)))
        (wcmatch (cdr (assoc 0 tdata)) "*TEXT")
      ); and
    ); or
    (sssetfirst nil (ssget "_X" (list '(0 . "*TEXT") (assoc 1 tdata)))); then
    (prompt "\nYou must select one Text or Mtext object."); else
  ); if
)

 

It works either with or without pre-selection [noun-verb or verb-noun operation].  If a pre-selection includes one Text/Mtext object [whether or not it also includes any other kind(s) of object(s)], it uses the content of that.  If a pre-selection contains no Text/Mtext objects or more than one, it clears the selection and asks you to select one, the same as if you entered the command with no pre-selection.  If there is no pre-selection, it simply asks you to select one.

 

If the source is Mtext with any internal formatting, it will find others with exactly the same internal formatting, but not plain Text or un-formatted Mtext with otherwise the same content.  If the source is plain Text or un-formatted Mtext, it finds both Text and un-formatted Mtext objects with the same content.

 

It's case-sensitive.

 

* There is a way to get the content in FILTER from a selected object, but you then need to weed out all other properties of that object that you want ignored from the filter list.  The "Text" object you can include covers both Text and Mtext [Mtext is not in the list], and I find if I don't include that, but only the "Text value" entry, it will also find things like Dimensions with that content as a text override.

Kent Cooper, AIA
Message 6 of 8

komondormrex
Mentor
Mentor

hi there,

check this one. custom st command will seek max number of similar contents entries in the selected before run m_texts or if nothing selected suggest to select those. then it gets gripped corresponding entities.

;**************************************************************************************

(defun c:st (/ text_sset text_str text_list max_entry_sset)

	;**********************************************************************************

	(defun remove_duplicates (_list / duplicateless_list)
		(while _list
			(if (not (member (setq list_element (car _list)) (setq _list (cdr _list))))
				(setq duplicateless_list (cons list_element duplicateless_list))
			)
		)
		(reverse duplicateless_list)
	)

	;**********************************************************************************

	(defun parse_str_list (str_list / unique_str_list)
		(setq str_list (acad_strlsort str_list)
			  unique_str_list (remove_duplicates str_list)
		)
		(mapcar '(lambda (each_str)
					(cons (- (length str_list) (length (vl-remove each_str str_list)))
						  each_str
					)
				 )
				 unique_str_list
		)
	)

	;**********************************************************************************

	(defun find_max_entry (text_sset list_var / parsed_str_list)
		(cdr (assoc
				(apply 'max
					   (mapcar 'car
								(setq parsed_str_list
									 (parse_str_list
										(mapcar '(lambda (ename) (cdr (assoc 1 (entget ename))))
												 (set list_var (vl-remove-if
												 					'listp
																	(mapcar 'cadr (ssnamex text_sset))
															   )
												 )
										)
									 )
								)
					   )
				)
				parsed_str_list
			 )
		)
	)

	;**********************************************************************************

	(setvar 'pickfirst 1)
	(if (null (setq text_sset (ssget '((0 . "*text")))))
	   	(setq text_sset (ssget '((0 . "*text"))))
	)
	(sssetfirst)
	(setq text_str (find_max_entry text_sset 'text_list)
		  text_list (vl-remove-if-not '(lambda (text) (= text_str (cdr (assoc 1 (entget text)))))
									   text_list
					)
		  max_entry_sset (ssadd)
	)
	(foreach text text_list (ssadd text max_entry_sset))
	(sssetfirst nil max_entry_sset)
	(vla-regen (vla-get-activedocument (vlax-get-acad-object)) acactiveviewport)
	(princ)
)

;**************************************************************************************
Message 7 of 8

S_S_SS
Advocate
Advocate
YES Sir
I know how to use filter command & quick select
but i need something to be easier and fastest than that
I've got the code that make that thanks
0 Likes
Message 8 of 8

S_S_SS
Advocate
Advocate
YES Sir
I know how to use filter command & quick select
but i need something to be easier and fastest than that
I've got the code that make that thanks
0 Likes