Jump to content

Recommended Posts

Posted

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

;)

Posted

Something like:

 
(setq sset (ssget "_X" (list (cons 0 "text")(cons 1 "banana"))))

Posted

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??

Posted

Hi Tharwat

I'd like to select all the specific text to count them.

Posted
Hi Tharwat

I'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)
)

Posted

Awesome, Thawart!!!

Your code is great, helped me a lot.

 

:D

Posted
Awesome, Thawart!!!

Your code is great, helped me a lot.

 

:D

 

I am happy to heat that . :D

 

Good luck .

Posted

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.;)

Posted

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

Posted

Also that have to be "DText" not MText.

Posted

Brilliant! :notworthy:

 

Many Thanks Brian.

I'll save a lot of time with this code.

 

:D

Posted

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.:)

Posted

I really appreciate the help.

 

Thank you Thawart, Fixo and BrianTFC.

 

8)

Posted
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 . :)

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...