Lisp to search every underlined > and replace with ≥

Lisp to search every underlined > and replace with ≥

anton_chmidt
Advocate Advocate
811 Views
11 Replies
Message 1 of 12

Lisp to search every underlined > and replace with ≥

anton_chmidt
Advocate
Advocate

Is this possible? Also < to 

text and mtext content would be a great start, but they might be even in mleaders and similar texts. 

0 Likes
Accepted solutions (2)
812 Views
11 Replies
Replies (11)
Message 2 of 12

Kent1Cooper
Consultant
Consultant

Which variety of ≥ would you want to use?  There's Alt+242, there's the Unicode \U+2265, there's the one you can get from the Symbols pull-down "Other" category in the Mtext editor, which comes out looking like this in entity data text content:
"{\\fSymbol|b0|i0|c2|p18;\\H0.95833x;³}"

 

It's complicated by the difference in entity-data character content between an underlined greater-than character in Mtext:

"{\\L>}"

vs. plain Text

"%%U>"

Kent Cooper, AIA
0 Likes
Message 3 of 12

anton_chmidt
Advocate
Advocate
I would want to use \U+2264 and \U+2265 since Alt+242 is not working in my region.
0 Likes
Message 4 of 12

Kent1Cooper
Consultant
Consultant

In quickie trial, this finds/selects/grips/highlights both Text and Mtext containing those variants:

(sssetfirst nil (ssget "_X" '((1 . "*{\\L>}*,*%%U>%%U*"))))

on the assumption that the > character is underlined by itself [no other characters within the underlining].

 

So, [minimally tested]:

 

(defun C:GTEsub (/ ss n ent edata); = Greater-Than-or-Equal character substitution
  (if (setq ss (ssget "_X" '((1 . "*{\\L>}*,*%%U>%%U*"))))
    (repeat (setq n (sslength ss)) ; then
      (setq
        ent (ssname ss (setq n (1- n)))
        edata (entget ent)
      ); setq
      (entmod
        (subst
          (cons 1
            (vl-string-subst
              "\U+2265"
              (if (member '(0 . "TEXT") edata) "%%U>%%U" "{\\L>}")
              (cdr (assoc 1 edata))
            ); ...subst
          ); cons
          (assoc 1 edata)
          edata
        ); subst
      ); entmod
    ); repeat
  ); if
  (prin1)
); defun

 

And similarly with the Less-Than-or-Equal character.

 

Would any Mtext/Text objects contain that more than once?  If so, there would need to be a (while) check for the presence of [another of] that original substring, and repeated substitution as long as it still finds it, since (vl-string-subst) will replace only the first instance in the string.

Kent Cooper, AIA
0 Likes
Message 5 of 12

anton_chmidt
Advocate
Advocate

OH wow! Thank you! So this also check and replace only if > is underlined and nothing around it?

So for example it would skip something like this? "This formula is True 1<2"
If so it is great! Because that feature I would wish to have for obvious reasons but assumed it would be impossible to add...But you added it even without asking!!

 

And yes there could be multiple >,< or both in one object. Could you please add the while-loop so it would check for multiples? Is there any downside in adding that while-loop?

0 Likes
Message 6 of 12

Kent1Cooper
Consultant
Consultant

@anton_chmidt wrote:

.... yes there could be multiple >,< or both in one object. Could you please add the while-loop so it would check for multiples? Is there any downside in adding that while-loop?


No downside that I can think of.  This seems to do that [again, minimally tested]:

 

(vl-load-com)
(defun C:GTEsub (/ ss n ent edata txt str); = Greater-Than-or-Equal character substitution
  (if (setq ss (ssget "_X" '((1 . "*{\\L>}*,*%%U>%%U*"))))
    (repeat (setq n (sslength ss)) ; then
      (setq
        ent (ssname ss (setq n (1- n)))
        edata (entget ent)
        txt (member '(0 . "TEXT") edata); T/nil [nil = Mtext]
        str (cdr (assoc 1 edata))
      ); setq
      (while (vl-string-search (if txt "%%U>%%U" "{\\L>}") str); still has it
        (entmod
          (subst
            (cons 1
              (setq str
                (vl-string-subst
                  "\U+2265"
                  (if txt "%%U>%%U" "{\\L>}")
                  str
                ); ...subst
              ); setq
            ); cons
            (assoc 1 edata)
            edata
          ); subst
        ); entmod
      ); while
    ); repeat
  ); if
  (prin1)
); defun

EDIT:  I suppose it would be possible to have one command that does that substitution for both ≥ and ≤ situations, collectively.  Is that something you would want to be able to do, or would you prefer to handle each on its own?

 

Kent Cooper, AIA
0 Likes
Message 7 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

@Kent1Cooper wrote:

.... it would be possible to have one command that does that substitution for both ≥ and ≤ situations, collectively.  Is that something you would want to be able to do...?


On the assumption that the answer is Yes, try the attached LGTOEsub.lsp with its LGTOES command [stands for Less- or Greater-Than-Or-Equal Substitution].

Kent Cooper, AIA
Message 8 of 12

anton_chmidt
Advocate
Advocate
Thank you very much! I truely appreciate your effort in helping me and others here. Sorry for delay in my answer, been busy at work. Anyway, I will do testing after the holidays.
0 Likes
Message 9 of 12

anton_chmidt
Advocate
Advocate
Have been using this lisp for a while now and it is working perfectly as inteded. But do you think it would be possible to make look in dimensions and alligned dimensions too? Often users has doubleclicked dimensions and added own text infront of measure value.
0 Likes
Message 10 of 12

Kent1Cooper
Consultant
Consultant

@anton_chmidt wrote:
.... do you think it would be possible to make look in dimensions and alligned dimensions too? ....

It already does.  Its selection is not limited by entity type, but only by text content containing one of the underlined < or > character possibilities.  It worked for me in a quick trial.  If it doesn't for you, post a small drawing containing a Dimension or two with such characters that don't get substituted -- maybe there's some additional way of underlining them that isn't part of what it looks for.

Kent Cooper, AIA
0 Likes
Message 11 of 12

anton_chmidt
Advocate
Advocate

Does it works for you with this file? 

0 Likes
Message 12 of 12

Kent1Cooper
Consultant
Consultant
Accepted solution

I see what happened.  Those Dimensions have the underlining done by adding %%U before and after the  <  or  >  character, as it's done in plain Text.  Dimension text is "Mtext-like" in certain ways, including in the editing options in the ribbon.  If I have a Dimension with  <  or  >  added as part of a text override, and if I select that character in editing the Dimension text and choose the Underline icon in the ribbon:

Kent1Cooper_0-1682434482878.png

it does the underlining with the Mtext approach:

"{\\L<}<>"

The routine expects the %%U approach only in plain Text, so for other object types it looks only for the {\\L approach.  So it works when the underlining is done by the icon in the ribbon [like editing Mtext], but not when it's done with %%U wrappers.

 

The oddest thing about it, to me, is that when editing Dimension text, you get the same editing ribbon as you do for Mtext, so I expect it to be the same, but it's not quite.  For some reason the %%U wrappers work to underline things in Dimension text, though they do not work in Mtext.  In Dimension text, for some reason you can underline in two ways, but in Text or Mtext, only one each.  I wasn't aware of that duality in Dimension text when I wrote the routine.

 

SO I took out the limitation of what it looks for by entity type, and the attached now looks for any of those ways of underlining, in any kind of object.  It works in your drawing, in quickie testing.

 

 

Kent Cooper, AIA
0 Likes