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

Remove text underline

29 REPLIES 29
Reply
Message 1 of 30
Anonymous
10966 Views, 29 Replies

Remove text underline

Anyone have a routine to remove underlining from multiple dtext & mtext
objects?
29 REPLIES 29
Message 2 of 30
jsowinski
in reply to: Anonymous

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
Message 3 of 30
Anonymous
in reply to: Anonymous

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
Message 4 of 30
Anonymous
in reply to: Anonymous

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
Message 5 of 30
Anonymous
in reply to: Anonymous

This update works quite nicely - thanks to Jim S. & Ken K
Message 6 of 30
Tom Smith
in reply to: Anonymous

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.
Message 7 of 30
Anonymous
in reply to: Anonymous

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.
Message 8 of 30
Tom Smith
in reply to: Anonymous

Probably the best solution for the OP would be to get hold of STRIPMTEXT. It allows removing only the underlining and nothing else.
Message 9 of 30
Anonymous
in reply to: Anonymous

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?
Message 10 of 30
Tom Smith
in reply to: Anonymous

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.
Message 11 of 30
Anonymous
in reply to: Anonymous

I didn't find a source to download StripMtext, but I found the code posted
here previously and used that. Some of the functions are defined locally and
not available outside the main routine (unless you wanted to edit and change
this, which I did not). Instead, I found the StripMtext function, which takes
a selection set. So I step through the text and mtext objects, process the
text objects, dump the mtext objects into a second selection set, and then
pass that to StripMtext. Result: Uline now does both. The text portion now
handles text with multiple underlines, by using wcmatch in a while loop. See
if this does it for you:

(load "stripmtext") ; Be sure it's on search path
(defun c:uline (/ ss1 ss2 num ent elist str)
; TEXT
(setq
ss1 (ssget '((0 . "*TEXT")))
ss2 (ssadd) ; empty sset for mtext only
num 0
)
(repeat (sslength ss1)
(setq
ent (ssname ss1 num) ; the entity
num (1+ num)
elist (entget ent) ; the entity data list
str (cdr (assoc 1 elist))
)
(if (= (cdr (assoc 0 elist)) "TEXT")
(progn
(while (wcmatch (strcase str) "*%%U*")
(setq
str (vl-string-subst "" "%%U" str)
str (vl-string-subst "" "%%u" str)
)
)
(setq str (subst (cons 1 str)(assoc 1 elist) elist))
(entmod str)
);progn
; MTEXT
(ssadd ent ss2) ; add the mtext to the sset
);if

);repeat

; MTEXT (if any selected)
(if (> (sslength ss2) 0) ; not still empty
(StripMtext ss2)
)

(princ)
)

Ken Krupa
Autodesk Authorized Developer
www.krupacadd.com


KDispoto wrote:
> 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?
Message 12 of 30
Tom Smith
in reply to: Anonymous

Great job, Ken.
Message 13 of 30
Anonymous
in reply to: Anonymous

I have a copy of StripMtext[3].lsp which is ver 3 in the path and get the
following error.

Command: (LOAD "C:/KD/Kd-acad/kd-Lisp/Uline.lsp")
StripMtext v3.05 loaded. Start command by typing "STRIPMTEXT" C:ULINE
Command: uline
Select objects: Specify opposite corner: 5 found
Select objects:
; error: no function definition: STRIPMTEXT


The 5 object were a combination of underlined mtext & text objects.
Yet if I enter Stripmtext afterwards at the command line the program works -
any suggestions?
Message 14 of 30
Tom Smith
in reply to: Anonymous

>; error: no function definition: STRIPMTEXT

In the version Ken had, that function wasn't declared local. In yours it is. Look in the file and get rid of the declaration:

(defun c:StripMtext ( /

; Functions

*error*
AcceptButton
ClearAllButton
MainDialog
SelectAllButton
Setup
;StripMtext <-- add a semi-colon to comment out this line.
Unformat
Message 15 of 30
Anonymous
in reply to: Anonymous

What Tom said won't quite do it, because you would need to run the StripMtext
command (c:StripMtext) once before the StripMtext function is defined. The
solution (shooting from the hip, since I don't have your version): in addition
to commenting out that line that Tom said, is to grab the entire StripMtext
function definition and move it outside of the c:StripMtext definition. Then
StripMtext will be available as soon as the file is loaded.

I suspect StripMtext probably calls the Unformat function, so you would need
to do the same to it as for StripMtext.

If you need help with this, either post the StripMtext file, or tell me how to
get it, and I'll take a look.

Ken Krupa

Tom Smith wrote:
>> ; error: no function definition: STRIPMTEXT
>
> In the version Ken had, that function wasn't declared local. In yours it is. Look in the file and get rid of the declaration:
>
> (defun c:StripMtext ( /
>
> ; Functions
>
> *error*
> AcceptButton
> ClearAllButton
> MainDialog
> SelectAllButton
> Setup
> ;StripMtext <-- add a semi-colon to comment out this line.
> Unformat
Message 16 of 30
Tom Smith
in reply to: Anonymous

Ken, you're right, thanks.

I was hoping it could be made to work as you had it, without having to edit STRIPMTEXT, but I guess that will be necessary.

To get around that kind of thing in my own lisps, I usually try to distinguish between the actual "working" routine (which can be called with parameters) and the "command" version (which solicits input from the user, then calls the working routine.) That way I can call the function from another routine if need be. Apparently that's how the STRIPMTEXT that you had was set up.
Message 17 of 30
Anonymous
in reply to: Anonymous

Well, I found version 3.0 and gave it a try. What I suggested did not work.
StripMtext now does a lot more, but there are built-in dependencies that do
not allow its inner workings to be used independently as they used to be.

A solution is to use the older version (2.1 is what I found initially). I
renamed the file to StripMtext21.lsp, and renamed the global functions the
same way - that way there would be no conflict if you wanted to use the newer
version (by itself) also. The revised file is attached. And the revised Uline
routine is this:

(load "stripmtext21") ; Be sure it's on search path
(defun c:uline (/ ss1 ss2 num ent elist str)
; TEXT
(setq
ss1 (ssget '((0 . "*TEXT")))
ss2 (ssadd) ; empty sset for mtext only
num 0
)
(repeat (sslength ss1)
(setq
ent (ssname ss1 num) ; the entity
num (1+ num)
elist (entget ent) ; the entity data list
str (cdr (assoc 1 elist))
)
(if (= (cdr (assoc 0 elist)) "TEXT")
(progn
(while (wcmatch (strcase str) "*%%U*")
(setq
str (vl-string-subst "" "%%U" str)
str (vl-string-subst "" "%%u" str)
)
);while
(setq str (subst (cons 1 str)(assoc 1 elist) elist))
(entmod str)
);progn
; MTEXT
(ssadd ent ss2) ; add the mtext to the sset
);if

);repeat

; MTEXT (if any selected)
(if (> (sslength ss2) 0) ; not still empty
(StripMtext21 ss2)
)

(princ)
)

Ken Krupa
Autodesk Authorized Developer
www.krupacadd.com


Tom Smith wrote:
> Ken, you're right, thanks.
>
> I was hoping it could be made to work as you had it, without having to edit STRIPMTEXT, but I guess that will be necessary.
>
> To get around that kind of thing in my own lisps, I usually try to distinguish between the actual "working" routine (which can be called with parameters) and the "command" version (which solicits input from the user, then calls the working routine.) That way I can call the function from another routine if need be. Apparently that's how the STRIPMTEXT that you had was set up.
Message 18 of 30
Anonymous
in reply to: Anonymous

Watch out for the word wrap
Message 19 of 30
sdoman
in reply to: Anonymous

Hi people,

I noticed some confusion about StripMtext and where to get the latest version.

The most current version of StripMtext is 3.09. This version exposes a function called Unformat written by John Uhden which does the actual work of removing formatting codes from Mtext objects. Thus by loading StripMtext you may then call Unformat from your own AutoLISP code or by script.

It can be downloaded here: http://cadabyss.wordpress.com/

Hope that helps. Thanks for the favorable comments and I wish I could hang out here all day and talk code with you.

Regards,
Steve Doman
Message 20 of 30
Tom Smith
in reply to: Anonymous

Steve, thanks for the info, and for the fine program.

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

Post to forums  

Autodesk Design & Make Report

”Boost