@tw1978.tw wrote:
Does anyone know how to create a underline text LISP as a shortcut?
If I have correctly understood, perhaps something like this for underline text toggle (untested)
(defun c:test (/ en ss st) (if (setq ss (ssget "_+.:E:S:L" '((0 . "TEXT")))) (progn (setq en (entget (ssname ss 0)) st (cdr (assoc 1 en)) ) (if (= (strcase (substr st 1 3)) "%%U") (entmod (subst (cons 1 (substr st 4)) (assoc 1 en) en)) (entmod (subst (cons 1 (strcat "%%u" st)) (assoc 1 en) en)) ) ) ) (princ) )
HTH
Henrique
Another, simple one:
(defun c:ult ( / s ) (if (setq s (ssget "_+.:E:S:L" '((0 . "TEXT") (1 . "~*%%[Uu]*")))) (entmod (list (cons -1 (ssname s 0)) (cons 1 (strcat "%%u" (cdr (assoc 1 (entget (ssname s 0)))))))) ) (princ) )
Here's a quirky question for you: Would you ever want to have such a routine fully underline Text whose content may be already but only partially underlined?
The suggestion from hmsilva looks only at whether the text content begins with the underlining code %%U, and adds that at the beginning if it doesn't. Since that same code is used to both start and end underlining, it would convert [for example]:
Text like this
into
Text like this
but would leave
Text like this
unchanged, rather than underlining all of it if that's what you would want.
And Lee Mac's routine, which looks at whether the content does not contain any %%U codes at all [whether at the beginning or elsewhere], would leave any kind of partial underlining as it is, rather than underline all of it.
It certainly would be possible to have a routine start by just removing all %%U codes, and put one at the beginning. Then, regardless of whether or not it had any underlining to begin with, partial or not, the end result would always be fully underlined.
Kent1Cooper wrote:
Here's a quirky question for you: Would you ever want to have such a routine fully underline Text whose content may be already but only partially underlined?
The suggestion from hmsilva looks only at whether the text content begins with the underlining code %%U, and adds that at the beginning if it doesn't. Since that same code is used to both start and end underlining, it would convert [for example]:
Text like this
into
Text like this
but would leave
Text like this
unchanged, rather than underlining all of it if that's what you would want.
...
It certainly would be possible to have a routine start by just removing all %%U codes, and put one at the beginning. Then, regardless of whether or not it had any underlining to begin with, partial or not, the end result would always be fully underlined.
Untested...
(defun c:test (/ en ss st) (if (setq ss (ssget "_+.:E:S:L" '((0 . "TEXT")))) (progn (setq en (entget (ssname ss 0)) st (cdr (assoc 1 en)) ) (if (wcmatch st "*%%[Uu]*") (progn (while (wcmatch st "*%%[Uu]*") (setq st (vl-string-subst "" "%%U" st)) (setq st (vl-string-subst "" "%%u" st)) ) (entmod (subst (cons 1 st) (assoc 1 en) en)) ) (entmod (subst (cons 1 (strcat "%%U" st)) (assoc 1 en) en)) ) ) ) (princ) )
HTH
Henrique