Jump to content

Need a lisp that only finds and highlight duplicate words (numbers or text string)??


goldy2000

Recommended Posts

15 hours ago, ronjonp said:

 


	   (or (vl-position (setq r (cdr (assoc 1 (entget x)))) f) (setq f (cons (strcat r ",") f)))

 

 

Sorry to nitpick Ron but -

 

Since r is concatenated with a comma when constructing the list f, vl-position will not prevent duplicate entries in the list... 

 

You also allow selection of Text & MText initially, but only include single-line Text in the final selection set.

 

Also watch out for wildcards - selecting text containing "*" could lead to undesired results! ;)

 

Maybe something like this -

(defun c:sstxt ( / f i l s x )
    (if (setq s (ssget (setq f (list '(0 . "*TEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))))
        (progn
            (repeat (setq i (sslength s))
                (setq i (1- i)
                      x (cons 1 (LM:escapewildcards (cdr (assoc 1 (entget (ssname s i))))))
                )
                (or (member x l) (setq l (cons x l)))
            )
            (sssetfirst nil (ssget "_X" (append f '((-4 . "<OR")) l '((-4 . "OR>")))))
        )
    )
    (princ)
)

;; Escape Wildcards  -  Lee Mac
;; Escapes wildcard special characters in a supplied string

(defun LM:escapewildcards ( str )
    (vl-list->string
        (apply 'append
            (mapcar
               '(lambda ( c )
                    (if (member c '(35 64 46 42 63 126 91 93 45 44))
                        (list 96 c)
                        (list c)
                    )
                )
                (vl-string->list str)
            )
        )
    )
)

(princ)

Of course, this still doesn't account for MText formatting or long text which occupies DXF group 3...

Edited by Lee Mac
Link to comment
Share on other sites

  • Replies 24
  • Created
  • Last Reply

Top Posters In This Topic

  • Lee Mac

    8

  • goldy2000

    5

  • ronjonp

    3

  • Saqib_theleo

    3

No worries Lee .. nice catch . I slapped that together with the existing code without really testing it :)

Thanks for the input!

Edited by ronjonp
Link to comment
Share on other sites

This also does not prevent duplicates:

(or (member x l) (setq l (cons (cons 1 x) l)))

 

BTW:

Isn't vl-position faster than member?

Edited by Roy_043
Link to comment
Share on other sites

4 hours ago, Roy_043 said:

This also does not prevent duplicates:


(or (member x l) (setq l (cons (cons 1 x) l)))

 

BTW:

Isn't vl-position faster than member?

 

Doh! Thanks @Roy_043 - I'll update the code.

 

vl-position is marginally faster but member is more readable in my opinion and better shows the intent of the code; I'm also half inclined to change it to (if (not (member ...))) rather than using (or).

Link to comment
Share on other sites

15 hours ago, Lee Mac said:

 

Sorry to nitpick Ron but -

 

Since r is concatenated with a comma when constructing the list f, vl-position will not prevent duplicate entries in the list... 

 

You also allow selection of Text & MText initially, but only include single-line Text in the final selection set.

 

Also watch out for wildcards - selecting text containing "*" could lead to undesired results! ;)

 

Maybe something like this -


(defun c:sstxt ( / f i l s x )
    (if (setq s (ssget (setq f (list '(0 . "*TEXT") (if (= 1 (getvar 'cvport)) (cons 410 (getvar 'ctab)) '(410 . "Model"))))))
        (progn
            (repeat (setq i (sslength s))
                (setq i (1- i)
                      x (cons 1 (LM:escapewildcards (cdr (assoc 1 (entget (ssname s i))))))
                )
                (or (member x l) (setq l (cons x l)))
            )
            (sssetfirst nil (ssget "_X" (append f '((-4 . "<OR")) l '((-4 . "OR>")))))
        )
    )
    (princ)
)

;; Escape Wildcards  -  Lee Mac
;; Escapes wildcard special characters in a supplied string

(defun LM:escapewildcards ( str )
    (vl-list->string
        (apply 'append
            (mapcar
               '(lambda ( c )
                    (if (member c '(35 64 46 42 63 126 91 93 45 44))
                        (list 96 c)
                        (list c)
                    )
                )
                (vl-string->list str)
            )
        )
    )
)

(princ)

Of course, this still doesn't account for MText formatting or long text which occupies DXF group 3...

hi Lee Mac,

thank you for adding Mtext and wildcard character ability to the code.

than you for your time and help.

Link to comment
Share on other sites

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