Jump to content

Recommended Posts

Posted

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! :beer:

Posted

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)

))

Posted

After testing myself found out code needs to be modified

Does not work properly now

Posted (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 by ronjonp
Posted
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!

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

Posted

Nicely done ronjonp. :)

 

There is no need to

 (setq out (ssadd <ent> out))

and just

(ssadd <ent> out)

is enough.

Posted

Ah yes :) .. sometimes I get a little crazy with the setq's.

Posted
Code updated above.

 

Amazing stuff! I will use this. Thank you!

Posted
Amazing stuff! I will use this. Thank you!

 

You're welcome :)

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