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

id duplicate text

12 REPLIES 12
SOLVED
Reply
Message 1 of 13
Migumby
1113 Views, 12 Replies

id duplicate text

Hello,

This is a routine that draws a line between duplicate text.

Would it be possible to have the line as bold red p-line so that its easier to identify.

thanks

 

;; 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)

12 REPLIES 12
Message 2 of 13
Kent1Cooper
in reply to: Migumby


@Migumby wrote:

....

This is a routine that draws a line between duplicate text.

Would it be possible to have the line as bold red p-line so that its easier to identify.

....


One way would be to change this line:

          (command "line" p1 p2 "")

to this instead:

          (command "_.pline" p1 "_width" somenumber "" p2 "_width" 0 "" "")

 

That will leave you with a current Polyline width setting [for the next Polyline you draw for some other purpose] of 0, rather than your find-it-more-easily width.  If you don't mind leaving it at that non-zero width, omit the "_width" 0 "" above.  You can also have the routine save the current width, whatever it is, and reset it afterwards, if you're interested.

 

The somenumber value could be a fixed number of your choice, or it could be calculated [for example, as a percentage of the viewing area height, or based on the drawing scale].

Kent Cooper, AIA
Message 3 of 13
hmsilva
in reply to: Migumby

And after

(command "_.pline" p1 "_width" ...

as Kent Cooper suggested, add

(command "._chprop" "_L" "" "_C" "1" "")

to change pline color to red

 

Henrique

EESignature

Message 4 of 13
Kent1Cooper
in reply to: hmsilva


@hmsilva wrote:

And after

(command "_.pline" p1 "_width" ...

as Kent Cooper suggested, add

(command "._chprop" "_L" "" "_C" "1" "")

to change pline color to red

 

Henrique


Of course -- I forgot that part.  But now it occurs to me that doing it at that point in the routine means potentially [if there are many duplicates] a lot of changing Polyline width back and forth, and a lot of assigning a color override to individual Polylines separately, when much of that can be avoided.  Try something like this
 

(defun c:fdt (/ plw col ss n m string1 string2 p1 p2) ;;Find Duplicate Text

  ;; should probably add error handler, but I'll leave that to you....

  (prompt "Select text items to examine: ")
  (setq

    plw (getvar 'plinewid)

    col (getvar 'cecolor)

    ss (ssget '((0 . "TEXT,MTEXT"))); <-- shorter way -- (ssget) honors (wcmatch) syntax

    n 0

  ); setq

  (setvar 'plinewidth somenumber)

  (setvar 'cecolor 1)

  (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 "_.pline" p1 p2 "")
          );progn
        );if
      );progn
      (setq m (1+ m))
    );while m
    (setq n (1+ n))
  );while n
  (setvar 'plinewid plw)

  (setvar 'cecolor col)

  (princ); moved here so 'cecolor value doesn't appear on Command: line

);defun

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

(princ)

Kent Cooper, AIA
Message 5 of 13
Migumby
in reply to: Kent1Cooper

Hi Kent,

On the first post that you gave me, I couldn’t seem to get a line weight working that was anything less than zero.

I tried the second posting and I don’t see any difference.

Maybe I’m doing something wrong?

I would like the p-line to be .05 in size.

thanks for all of your help.

Message 6 of 13
Migumby
in reply to: Migumby

woops,

i meant anything with a decimal not anything less that 0.

sorry

Message 7 of 13
Kent1Cooper
in reply to: Migumby


@Migumby wrote:

.... I couldn’t seem to get a line weight working that was anything less than zero.

....

I would like the p-line to be .05 in size.

....


I think it requires you to precede the decimal with a zero -- 0.05.

Kent Cooper, AIA
Message 8 of 13
Migumby
in reply to: Kent1Cooper

GREAT! THAT WORKS!

Thank you all for your help.

Message 9 of 13
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
....

  (setvar 'plinewidth somenumber)

....


Whoops -- that should be:

 

  (setvar 'plinewid somenumber)

Kent Cooper, AIA
Message 10 of 13
alanjt_
in reply to: Kent1Cooper

Faster and cleaner. I also took the liberty of assuming you don't care about matching case. If I am wrong, just remove the (strcase and corresponding closing paren.

 

(defun c:FDT (/ ss i data str asso lst)
  (if (setq ss (ssget '((0 . "MTEXT,TEXT"))))
    (progn
      (repeat (setq i (sslength ss))
        (setq data (entget (ssname ss (setq i (1- i))))
              str  (strcase (vl-string-right-trim " " (vl-string-left-trim " " (cdr (assoc 1 data)))))
              lst  (if (setq asso (assoc str lst))
                     (subst (cons str (cons (assoc 10 data) (cdr asso))) asso lst)
                     (cons (list str (assoc 10 data)) lst)
                   )
        )
      )

      (foreach item lst
        (if (> (length item) 2)
          (entmakex (append (list '(0 . "LWPOLYLINE")
                                  '(100 . "AcDbEntity")
                                  '(100 . "AcDbPolyline")
                                  (cons 90 (length (cdr item)))
                                  '(70 . 0)
                                  '(62 . 1) ; color
                                  '(43 . 0.05) ; width
                            )
                            (cdr item)
                    )
          )
        )
      )
    )
  )
  (princ)
)

 

Message 11 of 13
Migumby
in reply to: Migumby

Thanks greatly Kent.

It works great!

Message 12 of 13
alanjt_
in reply to: Migumby

So much for that. lol

Message 13 of 13
Kent1Cooper
in reply to: Kent1Cooper


@Kent1Cooper wrote:
...

  (setvar 'cecolor 1)

....


A belated further correction to the code in Post 4:

 

Change the above line to this:

 

  (setvar 'cecolor "1")

 

It needs to be a string, since there is the possibility of its being "Bylayer" or "Byblock" or "red" or ....

Kent Cooper, AIA

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

Post to forums  

Autodesk Design & Make Report

”Boost