Elektrik Posted December 5, 2021 Posted December 5, 2021 For example, there are texts containing area, m2, 50, door, etc. I could select them one by one thanks to QuickSelect, Text or MText, Contents and Wildcard Match, but I want to select them all at the same time like entering Area*, m2*, etc. and select all texts and mtexts containing those values like selecting them with wildcard match or a lisp to select text and mtext containing the values I want to select in the entire drawing, like if you select area:50m2, it would select area:75m2 or area 40m2 as well. Either one of these kinds of lips would help. Thanks in advance. Quote
mhupp Posted December 5, 2021 Posted December 5, 2021 (edited) This will select/highlight any text that starts with "Area" or ends with "m2". (defun C:seltxt (/ SS) (setq SS (ssget "_X" (list '(0 . "*TEXT") '(1 . "Area*,*m2") (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (princ) ) Edited December 5, 2021 by mhupp updated code. 3 Quote
Tharwat Posted December 5, 2021 Posted December 5, 2021 @mhupp as long as you are highlighting objects then I believe it would be much better to get the ones in current active space only than selecting all matching objects in the other invisible spaces. 1 1 Quote
mhupp Posted December 6, 2021 Posted December 6, 2021 (edited) Thinking more about this maybe it would be better to let the user decide what to search for. or use both top for common terms and this for not so common terms. You also have to input the * for wild cards and use , if you going to search for more then one term. its also important to note when typing the search terms you can't use spaces. (defun C:selTxt (/ SS txt) (setq txt (getstring "\nSearch Text for Terms: ")) ;hit enter for defult options. (if (eq txt "") (setq txt "Area*,*m2") ;set defult search options here ) (if (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 txt) (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (prompt (strcat "\nText doesn't contain " txt)) ) (princ) ) Example Search Text for: area*,*m2 This would work like above lisp. Search Text for: *area* This would select text that has the word "area" in it. Search Text for: *door This would select text that ends with "door" Search Text for: area*,*m2,*area*,*door This would select all 3 examples text in one go. Edited December 6, 2021 by mhupp combined the two commands into one. 2 1 Quote
Elektrik Posted December 7, 2021 Author Posted December 7, 2021 On 12/6/2021 at 3:38 AM, mhupp said: Thinking more about this maybe it would be better to let the user decide what to search for. or use both top for common terms and this for not so common terms. You also have to input the * for wild cards and use , if you going to search for more then one term. its also important to note when typing the search terms you can't use spaces. (defun C:selTxt (/ SS txt) (setq txt (getstring "\nSearch Text for Terms: ")) ;hit enter for defult options. (if (eq txt "") (setq txt "Area*,*m2") ;set defult search options here ) (if (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 txt) (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (prompt (strcat "\nText doesn't contain " txt)) ) (princ) ) Example Search Text for: area*,*m2 This would work like above lisp. Search Text for: *area* This would select text that has the word "area" in it. Search Text for: *door This would select text that ends with "door" Search Text for: area*,*m2,*area*,*door This would select all 3 examples text in one go. This lips is good, thanks. But, is there any way to enter multiple text, mtext values at the same time to select texts, mtexts containing either one of those values separately? Quote
mhupp Posted December 7, 2021 Posted December 7, 2021 I'm not understanding. you can search for multiple values at once just use a , in between them. Do you then want to cycle through the text that match the search one at a time? to edit them or something? Can you explain more what you want to do. Quote
Elektrik Posted December 7, 2021 Author Posted December 7, 2021 I want to select text with different content I will enter and move or delete them, as they are not useful to me. Quote
BIGAL Posted December 9, 2021 Posted December 9, 2021 You can use a simple (while and just add the txt to a string. (setq str "") (while (/= "" (setq txt (getstring "\nType text Enter to stop "))) (setq str (strcat str "," txt)) ) 3 Quote
Elektrik Posted December 9, 2021 Author Posted December 9, 2021 8 hours ago, BIGAL said: You can use a simple (while and just add the txt to a string. (setq str "") (while (/= "" (setq txt (getstring "\nType text Enter to stop "))) (setq str (strcat str "," txt)) ) I couldn't make it work, but thanks. Quote
Steven P Posted December 9, 2021 Posted December 9, 2021 56 minutes ago, Elektrik said: I couldn't make it work, but thanks. This works for me, selects text with user input as BigAl suggested and MHupps first bit of code (slight modification to both, using "(getstring T....)" to allow for spaces in the text string and (cons 1 str) which mhupp uses n his second code) (defun C:seltxt (/ SS str) (setq str "") (while (/= "" (setq txt (getstring T "\nType text Enter to stop "))) (setq str (strcat str "," txt)) ) (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 str) (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (princ) ) Noting that this is case sensitive, not sure how to do it otherwise, and it also accepts wold cards, search term Hello won't select 'Hello World' text in the drawing. but search Hello* should pick it up (and so should *llo wo*) 3 Quote
Elektrik Posted December 9, 2021 Author Posted December 9, 2021 1 hour ago, Steven P said: This works for me, selects text with user input as BigAl suggested and MHupps first bit of code (slight modification to both, using "(getstring T....)" to allow for spaces in the text string and (cons 1 str) which mhupp uses n his second code) (defun C:seltxt (/ SS str) (setq str "") (while (/= "" (setq txt (getstring T "\nType text Enter to stop "))) (setq str (strcat str "," txt)) ) (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 str) (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (princ) ) Noting that this is case sensitive, not sure how to do it otherwise, and it also accepts wold cards, search term Hello won't select 'Hello World' text in the drawing. but search Hello* should pick it up (and so should *llo wo*) This works great. Thank you all. 1 Quote
Steven P Posted December 9, 2021 Posted December 9, 2021 17 minutes ago, Elektrik said: This works great. Thank you all. 17 minutes ago, Elektrik said: This works great. Thank you all. Not me, I just copied and pasted BigAl and Mhupp..... 1 Quote
uzumaki narudin Posted December 22, 2021 Posted December 22, 2021 On 12/6/2021 at 7:38 AM, mhupp said: Thinking more about this maybe it would be better to let the user decide what to search for. or use both top for common terms and this for not so common terms. You also have to input the * for wild cards and use , if you going to search for more then one term. its also important to note when typing the search terms you can't use spaces. (defun C:selTxt (/ SS txt) (setq txt (getstring "\nSearch Text for Terms: ")) ;hit enter for defult options. (if (eq txt "") (setq txt "Area*,*m2") ;set defult search options here ) (if (setq SS (ssget "_X" (list '(0 . "*TEXT") (cons 1 txt) (cons 410 (getvar 'ctab))))) (sssetfirst nil ss) (prompt (strcat "\nText doesn't contain " txt)) ) (princ) ) Example Search Text for: area*,*m2 This would work like above lisp. Search Text for: *area* This would select text that has the word "area" in it. Search Text for: *door This would select text that ends with "door" Search Text for: area*,*m2,*area*,*door This would select all 3 examples text in one go. dear mate, can you add automatically delete those selected text at the end of this lisp ? if would be great Quote
exceed Posted December 22, 2021 Posted December 22, 2021 17 minutes ago, uzumaki narudin said: dear mate, can you add automatically delete those selected text at the end of this lisp ? if would be great output of this routine is selection. so, just add (command "erase" ) before (princ), after ) in the last section 1 1 Quote
uzumaki narudin Posted December 22, 2021 Posted December 22, 2021 5 minutes ago, exceed said: output of this routine is selection. so, just add (command "erase" ) before (princ), after ) in the last section thanks mate.. working Quote
Juan440 Posted May 27 Posted May 27 Bonjour, auriez-vous un lisp pour sélectionner tous les textes et tous les textes multiples du fichier en même temps, au lieu de procéder à 2 sélections rapides l'une après l'autre svp? Merci Juan Quote
Nikon Posted May 27 Posted May 27 (edited) 5 hours ago, Juan440 said: Bonjour, auriez-vous un lisp pour sélectionner tous les textes et tous les textes multiples du fichier en même temps, au lieu de procéder à 2 sélections rapides l'une après l'autre svp? Maybe this will do? First, specify the sample text, then specify the search window. ;; author koMon 10.11.2024 ;; Lisp select mtexts (including multi-line text) according to the specified sample text (defun c:Sel-mtxt-filter ( ) (setq pattern (getpropertyvalue (car (entsel "\nSample MText for filtering: ")) "text") mtext_filtered_sset (ssadd) ) (if (setq mtext_sset (ssget '((0 . "mtext")))) (sssetfirst nil (foreach mtext (vl-remove-if-not '(lambda (mtext) (vl-string-search pattern (getpropertyvalue mtext "text"))) (vl-remove-if 'listp (mapcar 'cadr (ssnamex mtext_sset))) ) (ssadd mtext mtext_filtered_sset) ) ) ) (princ) ) Edited May 27 by Nikon Quote
Steven P Posted May 27 Posted May 27 Select all the text and mtext at once, you can use a wildcard in 'ssget',* (defun c:selecttxt ( / MySS) (setq MySS (ssget "_X" (list '(0 . "*TEXT")))) ) 1 Quote
Steven P Posted May 27 Posted May 27 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 ) 2 1 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.