Jump to content

Find ripetute text...create a list


itacad

Recommended Posts

Hello...I was looking for a lisp that would look for duplicate texts in a file ... and of course I found it in a past discussion of this forum!

Is it possible once found, to list them in the command line?

regards

 

 

Link to comment
Share on other sites


(defun c:TextDupes ( / a b d e i l s tl v)
  (if (setq s (ssget "_X" (list (cons 0 "TEXT") (cons 410 (if (= 1 (getvar 'CVPORT))(getvar 'CTAB) "Model")))))
    (progn (setq d (ssadd))
           (repeat (setq i (sslength s))
             (setq e (ssname s (setq i (1- i))) a (cdr (assoc 1 (entget e))))
             (cond ((setq b (cdr (assoc a l)))(ssadd b d)(ssadd e d))((setq l (cons (cons a e) l)))))
           (repeat (setq i (sslength d))
             (setq i (1- i)) (if (not (member (setq v (cdr (assoc 1 (entget (ssname d i))))) tl))(setq tl (cons v tl))))
           (mapcar '(lambda(x)(princ "\n")(princ x)) tl)
       )
   )
   (princ)
)

Link to comment
Share on other sites

In case you also want to grip the text elements, here is another

 

(defun c:TextDupes ( / a b d e i l s ) 
  (setq f (list))  ;; contains a list of the text strings that are duplicates
  (if (setq s
           (ssget "_X"
               (list
                   (cons 0 "TEXT")
                   (cons 410 (if (= 1 (getvar 'CVPORT)) (getvar 'CTAB) "Model"))
               )
           )
       )
       (progn
           (setq d (ssadd))
           (repeat (setq i (sslength s))
               (setq e (ssname s (setq i (1- i)))
                     a (cdr (assoc 1 (entget e)))
               )
               (cond
                   (   (setq  b (cdr (assoc a l)))
                       (ssadd b d)
                       (ssadd e d)
                       (if (not (member a f))
                         (setq f (append f (list a)))
                       )
                   )
                   (   (setq l (cons (cons a e) l))   )
               )
           )
           (sssetfirst nil d)
       )
  )
  (princ "\nDuplicates: ")
  (foreach a f
    (princ (strcat "\"" a "\" "  ))
  )
  (princ)
)
Edited by Emmanuel Delay
Link to comment
Share on other sites

15 hours ago, itacad said:

I was looking for a lisp that would look for duplicate texts in a file

Is it possible once found, to list them in the command line?

 

If you're only looking to list the duplicate text items at the command-line, the code can be simplified greatly, e.g.:

(defun c:dupetext ( / d i l s x )
    (if (setq s (ssget "_X" (list '(0 . "TEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model")))))
        (repeat (setq i (sslength s))
            (setq x (cdr (assoc 1 (entget (ssname s (setq i (1- i)))))))
            (cond
                (   (not (member x l)) (setq l (cons x l)))
                (   (not (member x d)) (setq d (cons x d)) (print x))
            )
        )
    )
    (princ)
)

 

Edited by Lee Mac
  • Thanks 1
Link to comment
Share on other sites

12 minutes ago, Lee Mac said:

 

If you're only looking to list the duplicate text items at the command-line, the code can be simplified greatly, e.g.:

 

 

You're absolutely right (of course you are :beer: )

Link to comment
Share on other sites

Just for fun:

(defun c:dupetext nil 
  (
    '((f L ) (foreach x (f L) (print x)))
    '( (L / v)
      (if L
        (append
          (if (member (setq v (car L)) (cdr L)) (list v))
          (f (vl-remove v (cdr L)))
        )
      )
    )
    (apply 'append
      (mapcar '(lambda (x) (if (= 1 (car x)) (list (cdr x))))
        (apply 'append
          (mapcar 'entget 
            (vl-remove 0
              (apply 'append
                (ssnamex 
                  (ssget "_X" (list '(0 . "TEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))
                )
              )
            )
          )
        )
      )
    )
  )
  (princ)
)

:playing:

 

Link to comment
Share on other sites

4 minutes ago, Grrr said:

Just for fun:

:playing:

 

 

looks like we must have a serious discussion about the definition of  'fun' :danger:

Edited by rlx
  • Funny 3
Link to comment
Share on other sites

thank you all...but today was just a bad day! at work I can no longer use autocad because it has been replaced with a cad based on autodesk oem...the consequence is that I can not use lisp, vba and I do not even have the express tools! ...how sad...😔

Link to comment
Share on other sites

29 minutes ago, itacad said:

thank you all...but today was just a bad day! at work I can no longer use autocad because it has been replaced with a cad based on autodesk oem...the consequence is that I can not use lisp, vba and I do not even have the express tools! ...how sad...😔

 

My sincerest condolences 😥

Link to comment
Share on other sites

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