Madruga_SP Posted March 26, 2013 Posted March 26, 2013 Hi guys, How Can I select text by the name? e.g. I have 100 texts in my drawing ( apple, banana, orange and grape) All the texts have the same properties, height, width, layer, color and etc. And just the name is different. How Can I do to select all texts called "banana"? Thanks in advance Quote
Tharwat Posted March 26, 2013 Posted March 26, 2013 (setq ss (ssget "_X" '((0 . "*TEXT")(1 . "banana")))) Quote
fixo Posted March 26, 2013 Posted March 26, 2013 Something like: (setq sset (ssget "_X" (list (cons 0 "text")(cons 1 "banana")))) Quote
Madruga_SP Posted March 26, 2013 Author Posted March 26, 2013 Sorry guys, I don't know how to use the code. (setq sset (ssget "_X" (list (cons 0 "text")(cons 1 "banana")))) <Selection set: 23c14> Could you help me, please?? Quote
Tharwat Posted March 26, 2013 Posted March 26, 2013 What you wanna do after selecting that specific texts ? Quote
Madruga_SP Posted March 26, 2013 Author Posted March 26, 2013 Hi Tharwat I'd like to select all the specific text to count them. Quote
Tharwat Posted March 26, 2013 Posted March 26, 2013 Hi TharwatI'd like to select all the specific text to count them. Hi . Check this out . (defun c:banana (/ ss) (if (setq ss (ssget "_X" '((0 . "*TEXT") (1 . "banana")))) (princ (strcat "\n You have " "< " (itoa (sslength ss)) " > of banana texts" ) ) ) (princ) ) Quote
Madruga_SP Posted March 26, 2013 Author Posted March 26, 2013 Awesome, Thawart!!! Your code is great, helped me a lot. Quote
Tharwat Posted March 26, 2013 Posted March 26, 2013 Awesome, Thawart!!! Your code is great, helped me a lot. I am happy to heat that . Good luck . Quote
BrianTFC Posted March 26, 2013 Posted March 26, 2013 If you wanted to count all of the text at once you can use the following code. you can also insert the list into autocad. ;TXTCNT.lsp - Count how many times each text entity appears. ; Display the results sorted in a dialog box. ; BY jeffery p sanders (defun C:TXTCNT () ;define a sort routine - Usage: (srt list) - Let's not go into this yet! It works. (defun srt (alist / n) (setq lcup nil rcup nil ) (defun cts (a b) (cond ((> a b) t) ((= a b) t) (t nil) ) ) (foreach n alist (while (and rcup (cts n (car rcup))) (setq lcup (cons (car rcup) lcup) rcup (cdr rcup) ) ) (while (and lcup (cts (car lcup) n)) (setq rcup (cons (car lcup) rcup) lcup (cdr lcup) ) ) (setq rcup (cons n rcup)) ) (append (reverse lcup) rcup) ) ;turn the command echo off (setvar "cmdecho" 0) ;setup a variable to hold the data (setq datalist (list)) ;select objects (if (setq eset (ssget)) (progn ;set a counter to the first item in the selection set (setq cntr 0) ;loop through each selected entity (while (< cntr (sslength eset)) ;grab the entity's name (setq en (ssname eset cntr)) ;grab the DXF group codes of the entity (setq enlist (entget en)) ;ignore the entity if it is not a TEXT entity (if (= "TEXT" (cdr (assoc 0 enlist))) (progn ;get the text value from the DXF Group Code (setq str (cdr (assoc 1 enlist))) ;setup a variable to check if the entity exist in the datalist list (setq existing 0) ;loop through the datalist to find out if it is a new entity that needs ;to be added to the list or if it already exist and it's counter needs ;to be incremented (foreach a datalist (if (= (car a) str) (setq existing 1) ) ) ;if the entity is new then (if (= existing 0) ;do this - Add the item to the datalist along with a counter that starts at 1 (setq datalist (append datalist (list (cons str 1)))) ;else it's cntr needs to be incremented (setq datalist (subst (cons str (+ 1 (cdr (assoc str datalist)))) (assoc str datalist) datalist ) ) ) ) ) ;increment the entity counter (setq cntr (+ cntr 1)) ) ) ) ;setup a variable to hold the data again, this time in a different fashion (setq newList (list)) ;rearrange the list (foreach a datalist (setq newList (append newList (list (strcat (substr (strcat (car a) " . . . . . . . . . . . . . . . . . . . . . . . . . . " ) 1 50 ) " - " (itoa (cdr a)) ) ) ) ) ) ;sort the list (setq newList (srt newList)) ;put up the dialog box (setq dcl_id (load_dialog "TXTCNT.dcl")) ;see if it is already loaded (if (not (new_dialog "TXTCNT" dcl_id)) (exit) ) ;add the data to the list in the dialog box (start_list "datalist") (mapcar 'add_list newList) (end_list) ;if an action event occurs, do this function (action_tile "cancel" "(setq ddiag 1)(done_dialog)") (action_tile "insert" "(setq ddiag 2)(done_dialog)") ;display the dialog box (start_dialog) ;if the cancel button was pressed - display message (if (= ddiag 1) (princ "\n \n ...TXTCNT Cancelled. \n ") ) (if(= ddiag 2) (progn (setq pt(getpoint "\n Insertion Point: ")) (foreach a newList (command "-style" "ARIAL" "ARIAL" "" "" "" "" "") (command "text" pt "" "" a) (setq pt(polar pt (* pi 1.5) (* (getvar "textsize") 1.25))) ) ) ) ;unload the dialog box (unload_dialog dcl_id) ;turn the command echo back on (setvar "cmdecho" 1) ;supress the last echo (princ) ) this lisp has save ton's of time for my coworkers and myself. Quote
Madruga_SP Posted March 26, 2013 Author Posted March 26, 2013 Hi Brian, Thanks for sharing the code, but didn't work. Command: TXTCNT Select objects: Specify opposite corner: 7 found Select objects: ; error: quit / exit abort Quote
BrianTFC Posted March 26, 2013 Posted March 26, 2013 Sorry about that it would help if i included the "DCL" file. TXTCNT.DCL Quote
Madruga_SP Posted March 26, 2013 Author Posted March 26, 2013 Brilliant! Many Thanks Brian. I'll save a lot of time with this code. Quote
BrianTFC Posted March 26, 2013 Posted March 26, 2013 You are quite welcome. you will find that there are alot of great people on this site willing to help. Tharwat is one of them, he has help me numurious times. Quote
Madruga_SP Posted March 26, 2013 Author Posted March 26, 2013 I really appreciate the help. Thank you Thawart, Fixo and BrianTFC. Quote
Tharwat Posted March 27, 2013 Posted March 27, 2013 Tharwat is one of them, he has help me numurious times. Thank you Brian , it is very kind of you to say that . I really appreciate the help. Thank you Tharwat, You're welcome anytime . 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.