mickeforsberg Posted April 5, 2018 Posted April 5, 2018 Hello, I posted this on the Autodesk forum also but I thought I might get a better response here. Is there any way to detect Mtext entries, or if not possible with Mtext, just text? Let's say I have hundreds of Mtext entries placed in my drawing, but they have to be unique. For instance: 1.100 1.101 1.102 1.103 1.104 And so on... Is there a way to quickly find duplicate entries and highlight them, or perhaps list them? For example if 1.100 is used twice in the drawing. I know I can use FIND, but as I do not know which string is duplicated, this would take forever as I had to put each string in to see if there is a duplicate, if I'm not mistaken? Any ideas? Thanks! Quote
DGRL Posted April 5, 2018 Posted April 5, 2018 Out of the blue No testing whatsoever (setq a (ssget "x" '((0 . "TEXT,MTEXT,RTEXT")))) (setq aa (if a (repeat (setq i (sslength a)) (setq l (cons (ssname a (setq i (1- i))) l)) ) )) (foreach x l (if (= (cdr (assoc 1 (entget x))) (vl-position (cdr (assoc 1 (entget x))) (cdr (assoc 1 (entget (car l)))))) (print x) )) Quote
DGRL Posted April 5, 2018 Posted April 5, 2018 After testing myself found out code needs to be modified Does not work properly now Quote
SLW210 Posted April 5, 2018 Posted April 5, 2018 Please read the Code Posting Guidelines and have your Code to be included in Code Tags.[NOPARSE] Your Code Here[/NOPARSE] = Your Code Here Quote
ronjonp Posted April 5, 2018 Posted April 5, 2018 (edited) Here's a quick example: (defun c:foo (/ e msg out s tm) (cond ((setq s (ssget "_A" '((0 . "MTEXT,TEXT")))) (setq s (mapcar '(lambda (x) (cons x (strcase (cdr (assoc 1 (entget x)))))) (mapcar 'cadr (ssnamex s)) ) ) (setq out (ssadd)) (while (setq e (car s)) (setq s (cdr s)) (if (setq tm (vl-remove-if-not '(lambda (x) (wcmatch (cdr e) (cdr x))) s)) (progn (setq msg (cons (cons (cdr e) (1+ (length tm))) msg)) (foreach x (append (list e) tm) (setq out (ssadd (car x) out)) (setq s (vl-remove x s))) ) ) ) (sssetfirst nil out) (mapcar 'print (vl-sort msg '(lambda (a b) (< (car a) (car b))))) ) ) (princ) ) Edited April 5, 2018 by ronjonp Quote
mickeforsberg Posted April 5, 2018 Author Posted April 5, 2018 Here's a quick example: This is exactly what I was looking for, thank you! Is it possible to list the strings it has found duplicates of? Just as a bonus! Quote
ronjonp Posted April 5, 2018 Posted April 5, 2018 This is exactly what I was looking for, thank you!Is it possible to list the strings it has found duplicates of? Just as a bonus! Code updated above. Quote
Tharwat Posted April 5, 2018 Posted April 5, 2018 Nicely done ronjonp. There is no need to (setq out (ssadd <ent> out)) and just (ssadd <ent> out) is enough. Quote
ronjonp Posted April 5, 2018 Posted April 5, 2018 Ah yes .. sometimes I get a little crazy with the setq's. Quote
mickeforsberg Posted April 10, 2018 Author Posted April 10, 2018 Code updated above. Amazing stuff! I will use this. Thank you! Quote
ronjonp Posted April 10, 2018 Posted April 10, 2018 Amazing stuff! I will use this. Thank you! You're welcome 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.