itacad Posted January 17, 2019 Posted January 17, 2019 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 Quote
rlx Posted January 18, 2019 Posted January 18, 2019 (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) ) Quote
Emmanuel Delay Posted January 18, 2019 Posted January 18, 2019 (edited) 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 January 18, 2019 by Emmanuel Delay Quote
Lee Mac Posted January 18, 2019 Posted January 18, 2019 (edited) 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 January 18, 2019 by Lee Mac 1 Quote
rlx Posted January 18, 2019 Posted January 18, 2019 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 ) Quote
Grrr Posted January 18, 2019 Posted January 18, 2019 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) ) Quote
rlx Posted January 18, 2019 Posted January 18, 2019 (edited) 4 minutes ago, Grrr said: Just for fun: looks like we must have a serious discussion about the definition of 'fun' Edited January 18, 2019 by rlx 3 Quote
itacad Posted January 18, 2019 Author Posted January 18, 2019 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... Quote
rlx Posted January 18, 2019 Posted January 18, 2019 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 Quote
itacad Posted January 21, 2019 Author Posted January 21, 2019 I was able to try the various lisp on another computer ... they all work perfectly, thanks again! 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.