Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How to find duplicate text string ?

23 REPLIES 23
Reply
Message 1 of 24
Anonymous
13930 Views, 23 Replies

How to find duplicate text string ?

Dear All,

In order to avoid duplicate text string in different places in the same drawing, I would like to have such a tool to find duplicate text string.

For instance, I want to put numbering of some connection lines, I do not want to have different lines but have same number by mistype.

Is there anybody could help me ?

TIA,
Wiku
23 REPLIES 23
Message 2 of 24
Anonymous
in reply to: Anonymous

What do you want to do with duplicate strings if found?

Joe Burke


wrote in message news:5622298@discussion.autodesk.com...
Dear All,

In order to avoid duplicate text string in different places in the same drawing, I
would like to have such a tool to find duplicate text string.

For instance, I want to put numbering of some connection lines, I do not want to have
different lines but have same number by mistype.

Is there anybody could help me ?

TIA,
Wiku
Message 3 of 24
Anonymous
in reply to: Anonymous

To avoid any duplicate numbers in different places in the same drawing...

I used to draw a lot of electrical diagram which has different number of each line..

So, by the tool, I would like to check whether there are some duplicate number or not.

TIA,
Wiku
Message 4 of 24
Anonymous
in reply to: Anonymous

Here's a quick and dirty LISP that draws a line between each pair of
identical TEXT or MTEXT entities. You can decide what to do with the
offending entities after that.

-Bill

==========

weechoo wrote:
> Dear All,
>
> In order to avoid duplicate text string in different places in the same drawing, I would like to have such a tool to find duplicate text string.
>
> For instance, I want to put numbering of some connection lines, I do not want to have different lines but have same number by mistype.
>
> Is there anybody could help me ?
>
> TIA,
> Wiku
>
Message 5 of 24
Anonymous
in reply to: Anonymous

thank you Bill....
Message 6 of 24
Anonymous
in reply to: Anonymous

Sweet. I've been looking for something like this.
You're my hero. 😄


Melanie Perry
***not all who wander are lost***
http://mistressofthedorkness.blogspot.com

Bill Gilliss wrote:
> Here's a quick and dirty LISP that draws a line between each pair of
> identical TEXT or MTEXT entities. You can decide what to do with the
> offending entities after that.
>
> -Bill
>
> ==========
>
> weechoo wrote:
>> Dear All,
>>
>> In order to avoid duplicate text string in different places in the same drawing, I would like to have such a tool to find duplicate text string.
>>
>> For instance, I want to put numbering of some connection lines, I do not want to have different
> lines but have same number by mistype.
>> Is there anybody could help me ?
>>
>> TIA,
>> Wiku
>>
Message 7 of 24
Anonymous
in reply to: Anonymous

Happy to be of service, ma'am.

===========

Wanderer wrote:
> Sweet. I've been looking for something like this.
> You're my hero. 😄
>
>
> Melanie Perry
> ***not all who wander are lost***
>
>>>
Message 8 of 24
Anonymous
in reply to: Anonymous

Bill,

A minor change which probably applies to the original question.

(if (eq (strcase string1) (strcase string2))

So the test is not case sensitive.

Joe Burke
Message 9 of 24
Anonymous
in reply to: Anonymous


This does't draw lines, just displays a summary
report,

but also shows another way to do what your code
does,

that would be much faster on large datasets:


;; Given the list (1 2 1 1 3 2 5 3 4 5 3),
;;
;; (combine (1 2 1 1 3 2 5 3 4 5 3) '> '= )
;;
;; returns ((1 1 1) (2 2) (3 3 3) (4) (5 5))
;;
;; The input list does not need to be atoms,

(defun combine (inlist is-greater is-equal / sorted current result )
(setq sorted (sort inlist is-greater))
(setq current (list (car sorted)))
(foreach item (cdr sorted)
(if (apply is-equal (list item (car current)))
(setq current (cons item current))
(progn
(setq result (cons current result))
(setq current (list item))
)
)
)
(cons current result)
)

;; can be used for list of most kinds of atoms:

(defun atomic-combine (lst)
(combine lst '> 'eq)
)
(defun sort (lst predicate)
   (mapcar '(lambda (x) (nth x lst)) (vl-sort-i lst predicate))
)

;; simplified example for TEXT only (no MTEXT)

(defun C:REPORT-DUPLICATE-TEXT (/ ss items i e )
(if (setq ss (ssget '((0 . "TEXT"))))
(progn
(repeat (setq i (sslength ss))
(setq e (ssname ss (setq i (1- i))))
(setq items
(cons
(cons e (strcase (vl-string-trim " " (cdr (assoc 1 (entget e))))))
items
)
)
)
(setq items
(combine items
'(lambda (a b)
(> (cdr a) (cdr b))
)
'(lambda (a b)
(eq (cdr a) (cdr b))
)
)
)
(textscr)
(princ "\n\n")
(foreach item items
(if (> (length item) 1)
(princ
(strcat "\nFound " (itoa (length item))
" occurances of: " (cdar item)
                  )
)

)
)
)
)
(princ)
)

        



 

AcadXTabs: MDI Document Tabs for AutoCAD 2008
Supporting
AutoCAD 2000 through 2008

size=1>http://www.acadxtabs.com


Here's a quick and dirty LISP that draws a
line between each pair of
identical TEXT or MTEXT entities. You can decide
what to do with the
offending entities after
that.

-Bill

==========

weechoo wrote:
> Dear
All,
>
> In order to avoid duplicate text string in different places
in the same drawing, I would like to have such a tool to find duplicate text
string.
>
> For instance, I want to put numbering of some connection
lines, I do not want to have different
lines but have same number by
mistype.
>
> Is there anybody could help me ?
>
>
TIA,
> Wiku
>
Message 10 of 24
Anonymous
in reply to: Anonymous

thanks again...
Message 11 of 24
Anonymous
in reply to: Anonymous

what is (-4 . "
Message 12 of 24
Anonymous
in reply to: Anonymous

wrote in message news:5625709@discussion.autodesk.com...
what is (-4 . "

Look in the Visual Lisp developers guide under "Logical Grouping" for an explanation.
I assume you are referring to the code written by Bill Gilliss, in which case using
(ssget '((0 . "TEXT,MTEXT"))) would have also worked.

Regards,

Mel
Message 13 of 24
Anonymous
in reply to: Anonymous

I need a code that only selects similar text without doing anything else. Just mere highlight. Is it possible?

Message 14 of 24
cole.debolt
in reply to: Anonymous

This was very helpful. It covers most of what I need. Is it easy to write an exception in this file where I could say, exclude a string value?? I'm new to Lisp routines. I have a lot of experience with mvba, sql, just trying to learn here.

Thank you,

 

Message 15 of 24
pbejse
in reply to: cole.debolt


@cole.debolt wrote:

This was very helpful. It covers most of what I need. Is it easy to write an exception in this file where I could say, exclude a string value?? I'm new to Lisp routines. I have a lot of experience with mvba, sql, just trying to learn here.

Thank you,

 


You can use this filter 

 

(ssget "_X" '((0 . "TEXT")(1 . "~BANANA")))

 

simply put, the tilde "~" symbol means grab everything else but.

 

 

 

Message 16 of 24
cole.debolt
in reply to: pbejse

I'm using this:

;; This AutoLISP routine examines all the user-selected TEXT and MTEXT items,
;; and draws a line on the current layer between any two that have identical
;; string values.
;; Leading and trailing blanks spaces are ignored.
;; %% modifiers, like %%u, are not ignored.
;; Upper- and lower-case differences are not ignored.

(defun c:fdt () ;;Find Duplicate Text

(prompt "Select text items to examine: ")
(setq ss (ssget '((-4 . "<OR") (0 . "TEXT") (0 . "MTEXT") (-4 . "OR>"))))

(setq n 0)

(while
  (< n (sslength ss))
  (setq string1 (cdr (assoc 1 (entget (ssname ss n)))))
  (setq string1 (vl-string-right-trim " " (vl-string-left-trim " " string1)))
  (setq m (1+ n))

  (while
    (< m (sslength ss))
    (progn
      (setq string2 (cdr (assoc 1 (entget (ssname ss m)))))
      (setq string2 (vl-string-right-trim " " (vl-string-left-trim " " string2)))
      (if (= string1 string2)
        (progn
          (setq p1 (cdr (assoc 10 (entget (ssname ss n)))))
          (setq p2 (cdr (assoc 10 (entget (ssname ss m)))))
          (command "line" p1 p2 "")
          );progn
         );if
       );progn
       (setq m (1+ m))
     );while m
 
     (setq n (1+ n))
   );while n
  
);defun

(princ "Type FDT to run the Find_Dup_Text routine.")
(princ)

 

So can I just add what you suggested somewhere? This is pretty complex for the few I've done. lol

Message 17 of 24
pbejse
in reply to: cole.debolt

This will exclude the string BANANA and MANGO

(setq ss (ssget '((0 . "TEXT,MTEXT")(-4 . "<NOT") (1 . "BANANA,MANGO")(-4 . "NOT>"))))

 

Message 18 of 24
cole.debolt
in reply to: pbejse

I guess what I was asking is: Can I add this to my existing lisp above, I'm not sure where to add it. I tried it once... I'm trying to exclude an inch " symbol so it doesn't grab all my pipe sizes.
I'm not sure where to add your line in my code. I'm just guessing right now. Thank you
Message 19 of 24
pbejse
in reply to: cole.debolt


@cole.debolt wrote:
I guess what I was asking is: Can I add this to my existing lisp above, I'm not sure where to add it. I tried it once... I'm trying to exclude an inch " symbol so it doesn't grab all my pipe sizes.
I'm not sure where to add your line in my code. I'm just guessing right now. Thank you

 

(defun c:fdt () ;;Find Duplicate Text

(prompt "Select text items to examine: ")
(setq ss (ssget '((0 . "TEXT,MTEXT")(1 . "~*\"*"))))

(setq n 0)
(while
  (< n (sslength ss))
  (setq string1 (cdr (assoc 1 (entget (ssname ss n)))))
  (setq string1 (vl-string-right-trim " " (vl-string-left-trim " " string1)))
  (setq m (1+ n))

  (while
    (< m (sslength ss))
    (progn
      (setq string2 (cdr (assoc 1 (entget (ssname ss m)))))
      (setq string2 (vl-string-right-trim " " (vl-string-left-trim " " string2)))
      (if (= string1 string2)
        (progn
          (setq p1 (cdr (assoc 10 (entget (ssname ss n)))))
          (setq p2 (cdr (assoc 10 (entget (ssname ss m)))))
          (command "line" p1 p2 "")
          );progn
         );if
       );progn
       (setq m (1+ m))
     );while m
     (setq n (1+ n))
   );while n  
)

we Happy now? 🙂 

 

Message 20 of 24
john.uhden
in reply to: pbejse

Y'all better watch it with this one.

I'm glad that Joe Burke is involved.

MTEXT can contain formatting codes with plenty of numbers that can be repeated galore, and the OP is looking for duplicate numbers.  So it strikes me that one must compare the content of unformatted strings to be able to focus on the remaining numeric content.

While I created the original @Anonymous function, Joe and Steve Doman took the process to a higher level, so his input here is seriously important.

At least I doubt that "\\P" or "\n" is an issue here because I would think that no numeric string would be broken over sequential lines of text, as in...

"... <blah><blah> shall be no less than 1.

35 mm."

John F. Uhden

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost