Anuncios

The Autodesk Community Forums has a new look. Read more about what's changed on the Community Announcements board.

Kent1Cooper
en respuesta a: sam_underdown


@sam_underdown wrote:

.... Is it possible to create a similar lisp routine where it removes the underline, rather than applying it? .... 


Quickly, with minimal testing:

(defun C:UUT (/ ss n edata); = Un-Underline Text(s)
  ;; to remove all underlining from Text objects
  (if (setq ss (ssget "_:L" '((0 . "TEXT"))))
    (repeat (setq n (sslength ss)); then
      (setq
        edata (entget (ssname ss (setq n (1- n))))
        txt (cdr (assoc 1 edata))
      ); setq
      (while (wcmatch txt "*%%U*")
        (setq txt (vl-string-subst "" "%%U" txt))
      ); while
      (entmod (subst (cons 1 txt) (assoc 1 edata) edata))
    ); repeat
  ); if
  (princ)
); defun

(defun C:UUMT (/ ss n edata); = Un-Underline MText(s)
  ;; to remove underlining from Mtext whose ENTIRE content is underlined
  (if (setq ss (ssget "_:L" '((0 . "MTEXT") (1 . "{\\L*"))))
    (repeat (setq n (sslength ss)); then
      (setq
        edata (entget (ssname ss (setq n (1- n))))
        txt (cdr (assoc 1 edata))
      ); setq
      (entmod
        (subst
          (cons 1 (substr txt 4 (- (strlen txt) 4)))
          (assoc 1 edata)
          edata
        ); subst
      ); entmod
    ); repeat
  ); if
  (princ)
); defun

But NOTE the description for UUMT, that it's for Mtext whose entire content is underlined [just as the earlier routines were built to apply underlining only to entire content].  It depends on its content starting with "{\\L"  and ending with "}".  If it starts with underlined content but the underlining doesn't go under all of it, it will lose the last "real" character in place of losing the "}", because it just takes off the last character, whatever that is.

 

Part of "minimal testing" is that I looked at combinations of underline and color formatting, and found that if both are applied from the beginning of the content, the underlining format code always seems to come before the color code, no matter in which order they were applied, so it seems to appropriately take off the underlining code but leave the color code.  But if the underlining doesn't go all the way, odd stuff is left in the text string at the point where it ended, though the visible object looks right.  I did not try other kinds of formatting [e.g. tracking, width factor, obliquing] for their formatting-code relationships to underlining.

 

In the case of plain Text, UUT doesn't care whether the entire content is underlined -- it removes all underline-code content, starting and stopping, wherever and however many there are.

Kent Cooper, AIA