Visual LISP, AutoLISP and General Customization

Visual LISP, AutoLISP and General Customization

Reply
*KDispopto
Message 1 of 23 (1,022 Views)

Remove text underline

1022 Views, 22 Replies
10-09-2007 10:48 AM
Anyone have a routine to remove underlining from multiple dtext & mtext
objects?
Valued Contributor
jsowinski
Posts: 63
Registered: ‎04-12-2007
Message 2 of 23 (1,022 Views)

Re: Remove text underline

10-09-2007 02:10 PM in reply to: *KDispopto
Hi-
Here is some simple code that might do what you want. Hope this helps.

Jim

(defun c:uline ()

(setq sset (ssget '((0 . "*text"))))
(setq num 0)
(repeat (sslength sset)
(if (= (cdr(assoc 0(entget(ssname sset num)))) "TEXT")
(progn
(setq ent (entget(ssname sset num)))
(setq sub (cdr(assoc 1 ent)))
(setq sub (vl-string-subst "" "%%u" sub))
(setq sub (subst(cons 1 sub)(assoc 1 ent) ent))
(entmod sub)
(setq num (1+ num))
)
)
(if (= (cdr(assoc 0(entget(ssname sset num)))) "MTEXT")
(progn
(setq ent (entget(ssname sset num)))
(setq sub (cdr(assoc 1 ent)))
(setq sub (vl-string-subst "" "{\\L" sub))
(setq sub (vl-string-subst "" "}" sub))
(setq sub (subst(cons 1 sub)(assoc 1 ent) ent))
(entmod sub)
(setq num (1+ num))
)
)
); end repeat

); end defun
*KDispoto
Message 3 of 23 (1,022 Views)

Re: Remove text underline

10-16-2007 08:39 AM in reply to: *KDispopto
The routine work on Mtext just fine but when I selected a underlined Text
object I got the following error
= = = = =
Command: ULINE
Select objects: 1 found
Select objects:
; error: bad argument type: lentityp nil
= = = =
I think it has something to do with the case of %%u vs %%U
Any suggesttions?

wrote in message news:5744874@discussion.autodesk.com...
Hi-
Here is some simple code that might do what you want. Hope this helps.

Jim

(defun c:uline ()

(setq sset (ssget '((0 . "*text"))))
(setq num 0)
(repeat (sslength sset)
(if (= (cdr(assoc 0(entget(ssname sset num)))) "TEXT")
(progn
(setq ent (entget(ssname sset num)))
(setq sub (cdr(assoc 1 ent)))
(setq sub (vl-string-subst "" "%%u" sub))
(setq sub (subst(cons 1 sub)(assoc 1 ent) ent))
(entmod sub)
(setq num (1+ num))
)
)
(if (= (cdr(assoc 0(entget(ssname sset num)))) "MTEXT")
(progn
(setq ent (entget(ssname sset num)))
(setq sub (cdr(assoc 1 ent)))
(setq sub (vl-string-subst "" "{\\L" sub))
(setq sub (vl-string-subst "" "}" sub))
(setq sub (subst(cons 1 sub)(assoc 1 ent) ent))
(entmod sub)
(setq num (1+ num))
)
)
); end repeat

); end defun
*Ken Krupa
Message 4 of 23 (1,022 Views)

Re: Remove text underline

10-16-2007 11:33 AM in reply to: *KDispopto
The the case of %%u vs %%U needed to be dealt with, but that was not the main
problem you were having. That was caused by having the two if statements. Say
you selected two text objects. At the second time through, num would be set to
2 in the text portion of code. Then in the next if statement, it would try to
get entity number two from sset, where only 0 and 1 are valid. That was your
error.

The solution: instead of two if statements, you only need one. Since you
selection is pre-filtered, each object must be either one or the other. Here
it is revised for that, and to handle %%u and %%U. (Also rearranged the way I
would do it, to avoid having the same code in two different sections.)

(defun c:uline (/ sset num ent sub)
(setq sset (ssget '((0 . "*text"))))
(setq num 0)
(repeat (sslength sset)
(setq
ent (entget (ssname sset num))
sub (cdr (assoc 1 ent))
)
(if (= (cdr (assoc 0 (entget (ssname sset num)))) "TEXT")
(setq ; TEXT
sub (vl-string-subst "" "%%U" sub)
sub (vl-string-subst "" "%%u" sub)
)
(setq ; MTEXT
sub (vl-string-subst "" "{\\L" sub)
sub (vl-string-subst "" "}" sub)
)
)
(setq
sub (subst (cons 1 sub)(assoc 1 ent) ent)
num (1+ num)
)
(entmod sub)
); end repeat
(princ)
)

Ken Krupa
Autodesk Authorized Developer
www.krupacadd.com



KDispoto wrote:
> The routine work on Mtext just fine but when I selected a underlined Text
> object I got the following error
> = = = = =
> Command: ULINE
> Select objects: 1 found
> Select objects:
> ; error: bad argument type: lentityp nil
> = = = =
> I think it has something to do with the case of %%u vs %%U
> Any suggesttions?
>
> wrote in message news:5744874@discussion.autodesk.com...
> Hi-
> Here is some simple code that might do what you want. Hope this helps.
>
> Jim
>
> (defun c:uline ()
>
> (setq sset (ssget '((0 . "*text"))))
> (setq num 0)
> (repeat (sslength sset)
> (if (= (cdr(assoc 0(entget(ssname sset num)))) "TEXT")
> (progn
> (setq ent (entget(ssname sset num)))
> (setq sub (cdr(assoc 1 ent)))
> (setq sub (vl-string-subst "" "%%u" sub))
> (setq sub (subst(cons 1 sub)(assoc 1 ent) ent))
> (entmod sub)
> (setq num (1+ num))
> )
> )
> (if (= (cdr(assoc 0(entget(ssname sset num)))) "MTEXT")
> (progn
> (setq ent (entget(ssname sset num)))
> (setq sub (cdr(assoc 1 ent)))
> (setq sub (vl-string-subst "" "{\\L" sub))
> (setq sub (vl-string-subst "" "}" sub))
> (setq sub (subst(cons 1 sub)(assoc 1 ent) ent))
> (entmod sub)
> (setq num (1+ num))
> )
> )
> ); end repeat
>
> ); end defun
*KDispoto
Message 5 of 23 (1,022 Views)

Re: Remove text underline

10-16-2007 11:43 AM in reply to: *KDispopto
This update works quite nicely - thanks to Jim S. & Ken K
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 6 of 23 (1,022 Views)

Re: Remove text underline

10-16-2007 12:27 PM in reply to: *KDispopto
Ken, that works if it's safe to assume that underlining is the only mtext formatting in use, and it only occurs once in a string.

But it only gets the first instance of the underlining code, and it plays havoc with any other formatting, by removing the first trailing curly brace } it sees.

To really do this right would be a challenge, along the lines of Steve's STRIPMTEXT.
*Ken Krupa
Message 7 of 23 (1,022 Views)

Re: Remove text underline

10-16-2007 01:21 PM in reply to: *KDispopto
You're right. I only dealt with the problems at hand and didn't look any deeper.

Tom Smith wrote:
> Ken, that works if it's safe to assume that underlining is the only mtext formatting in use, and it only occurs once in a string.
>
> But it only gets the first instance of the underlining code, and it plays havoc with any other formatting, by removing the first trailing curly brace } it sees.
>
> To really do this right would be a challenge, along the lines of Steve's STRIPMTEXT.
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 8 of 23 (1,022 Views)

Re: Remove text underline

10-16-2007 01:40 PM in reply to: *KDispopto
Probably the best solution for the OP would be to get hold of STRIPMTEXT. It allows removing only the underlining and nothing else.
*KDispoto
Message 9 of 23 (1,022 Views)

Re: Remove text underline

10-17-2007 04:24 AM in reply to: *KDispopto
StripMtext works great - however it only works on Mtext and Ken Krupa's
Uline lisp work fine on dtext..
Ultimately I'd like to use one toolbar button to remove the underline from
multiple lines of text which could be a mixture of mtext or dtext.

Would there be a way to have a toolbar button macro or separate lisp
combine/piggyback StripMtext with Uline.lsp?
Distinguished Contributor
Tom Smith
Posts: 3,729
Registered: ‎12-17-2003
Message 10 of 23 (1,022 Views)

Re: Remove text underline

10-17-2007 05:16 AM in reply to: *KDispopto
There's no such entitty as dtext. For a while, there was a command named DTEXT, which placed text "dynamically," but at this point DTEXT is nothing but a pgp alias for the TEXT command.

The simple uline routine has much the same weakness on text and mtext -- it only works when the entire string is underlined. Maybe that's an acceptable assumption. Try running it on a string that's partially underlined and you'll see the problem. It only removes the first instance of &&u in a string.

If that could be fixed, you could write a lisp which called either a text-fixing routine, or the UnFormat function from STRIPMEXT. This is the primary function which does the actual work, and it's documented in the lisp file.
Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.