Turn Off Case-sensitivity

Turn Off Case-sensitivity

Anonymous
Not applicable
2,328 Views
5 Replies
Message 1 of 6

Turn Off Case-sensitivity

Anonymous
Not applicable

I received this little routine to change a specified text string with a new text string.

However, it is case-sensitive and I have many dwgs where users may have typed differently: some all uppercase, others mixing uppercase and lowercase.

How may I modify this routine so it finds "OLDTEXT", not only in uppercase, but also lowercase, or even a mix of both?

Basically, how do I turn off case-sensitivity as it searches for "OLDTEXT" so it can gather all case forms of that string and then changed them to "NEWTEXT"?  Of course, I do not want "NEWTEXT" to follow the case format of the original "OLDTEXT", but rather use whatever is entered in the code of the routine.

 

Here is the routine as I have it now:

 

(defun c:chgtext   (/ tss tdata)

  (setq tss (ssget "X" (list (cons 1 "OLDTEXT"))))
  (repeat (sslength tss)
    (setq
      tdata (entget (ssname tss 0))
      tdata (subst (cons 1 "NEWTEXT") (assoc 1 tdata) tdata)
    ); end setq
    (entmod tdata)
    (ssdel (ssname tss1 0) tss1)
  ); end repeat

)

 

 

Thanks for your help.

0 Likes
Accepted solutions (1)
2,329 Views
5 Replies
Replies (5)
Message 2 of 6

Kent1Cooper
Consultant
Consultant
Accepted solution

@Anonymous wrote:

I received this little routine to change a specified text string with a new text string.

However, it is case-sensitive and I have many dwgs where users may have typed differently: some all uppercase, others mixing uppercase and lowercase.

How may I modify this routine so it finds "OLDTEXT", not only in uppercase, but also lowercase, or even a mix of both?

....


The (wcmatch)-type nature of checking text-string content in (ssget) filter lists can't be made non-case-sensitive, as far as I know.

 

A)  If the only possibilities are all-the-same-case [either kind] or capital-first-letter-only and the rest lower-case, it could probably be accommodated within the search, though it might be just as easy to go for B) in any case.

 

B)  You could search for anything with text content, and within the stepping through the resulting selection, do the check on whether it matches on each object by forcing everything to all upper-case to make the comparison.  [Also, you can (entmod) the (subst) result directly, rather than saving a modified tdata and then (entmod)-ing that.]  Try something like this [untested]:

(defun c:chgtext   (/ tss tdata)
  (setq tss (ssget "X" '(("*TEXT")))); possibly add Dimensions with override text, and/or Attdef's?
  (repeat (sslength tss)
    (setq tdata (entget (ssname tss 0)))
(if (= (strcase "OLDTEXT") (strcase (cdr (assoc 1 tdata)))) (entmod (subst (cons 1 "NEWTEXT") (assoc 1 tdata) tdata)) ); end if (ssdel (ssname tss1 0) tss1);;;;; do you mean tss rather than tss1 [twice]? ); end repeat )
Kent Cooper, AIA
0 Likes
Message 3 of 6

Anonymous
Not applicable

Thanks Kent,

Both for catching me on the tss1 twice and for helping me to solve this problem

I do not need to add dimensions in the selection set search, but I did need to add mtext so I modified the setq to the following and it works fine.

 

(defun c:chgtext   (/ tss tdata)

  (setq tss (ssget "_X" '((0 . "TEXT,MTEXT"))))
    (repeat (sslength tss)
      (setq tdata (entget (ssname tss 0)))
      (if (= (strcase "OLDTEXT") (strcase (cdr (assoc 1 tdata))))
        (entmod (subst (cons 1 "NEWTEXT") (assoc 1 tdata) tdata))
      ); end if
      (ssdel (ssname tss 0) tss)
    ); end repeat

)

 

Your support is greatly appreciated.

0 Likes
Message 4 of 6

dbroad
Mentor
Mentor

I think Kent has solved your problem but I am wondering why you are essentially rewriting the find command. It has a checkbox for case sensitivity and works well and works across xrefs and across layouts.

Architect, Registered NC, VA, SC, & GA.
0 Likes
Message 5 of 6

Anonymous
Not applicable

Thanks for your interest and let me explain my ultimate goal for this function.

 

I needed a lisp routine rather than the find command as it will be incorporated into a much larger lisp that will be run on hundreds of older drawings to bring these to a newly created standards format our company has designed.

In a perfect world the find command would have indeed worked for us, but we don't have that much time.

Also, there was too much chance of error that could be incorporated into the process if we have users initiate the find command and change the 26 permutations of the specific text strings I wish to change on all these drawings.

 

I only wish there was a way to incorporate the find command within lisp.

Now that would be a perfect world.

Well... almost perfect!

 

Thanks again

0 Likes
Message 6 of 6

dbroad
Mentor
Mentor

Figured as much.  Just thought I'd comment to make sure.

 

Here is another thread that discussed this.

 

http://forums.autodesk.com/t5/visual-lisp-autolisp-and-general/ignore-text-case-in-search/m-p/254694...

Architect, Registered NC, VA, SC, & GA.
0 Likes