Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Creating undeline text LISP Routine

6 REPLIES 6
Reply
Message 1 of 7
tw1978.tw
1547 Views, 6 Replies

Creating undeline text LISP Routine

Does anyone know how to create a underline text LISP as a shortcut?

6 REPLIES 6
Message 2 of 7
hmsilva
in reply to: tw1978.tw


@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

EESignature

Message 3 of 7
Anonymous
in reply to: tw1978.tw

Do a search for Addtext.lsp in this forum. It works on Text only. Type "%%u" for the prefix and leave the suffix blank. Select your objects and it should work. It won't work on MText entities. HTH
Message 4 of 7
Lee_Mac
in reply to: tw1978.tw

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)
)
Message 5 of 7
Kent1Cooper
in reply to: tw1978.tw

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.

Kent Cooper, AIA
Message 6 of 7
Anonymous
in reply to: Kent1Cooper

That's why I didn't create one years ago when it crossed my mind, too many underlining variations.
Message 7 of 7
hmsilva
in reply to: tw1978.tw


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

EESignature

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost