Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Unformatting MTEXT

745 views
Skip to first unread message

John Uhden

unread,
Apr 1, 2003, 11:43:55 PM4/1/03
to
Having a reason to compare the value of groups of Mtext/Text in an Xref to
groups of Mtext/Text in the host drawing, I decided to attack the Mtext
formatting, in hopes of reducing it to a simple string equivalent. Tony said it
was difficult with AutoLisp, but I hope he was referring only to find *and*
replace algorithms. While risking public ridicule, I'd appreciate it if you
sages would test and comment (easy now, Tony).

;;===========================================================
;; UNFORMAT.LSP (c)2003, John F. Uhden, Cadlantic/CADvantage
;; v1.0 (04-01-03)
;; Removes MTEXT formatting with option to retain the "\\P" LineFeeds
;;
;; Arguments:
;; Mtext - either an Ename or VLA-Object
;; KeepLF - nil (discard LineFeeds) non-nil (retain LineFeeds)
;;
;; NOTES:
;; Only R15 or higher.
;; v1.0 is only the first attempt.
;; We can always embellish the code with additional options.
;; Yes, it can probably be sped up using integers, but this is legible.
;;
(defun UnFormat (Mtext KeepLF / Text Str)
(vl-load-com)
(cond
((= (type Mtext) 'VLA-Object))
((= (type Mtext) 'ENAME)
(setq Mtext (vlax-ename->vla-object Mtext))
)
(1 (setq Mtext nil))
)
(and
Mtext
(= (vlax-get Mtext 'ObjectName) "AcDbMText")
(setq Mtext (vlax-get Mtext 'TextString))
(setq Text "")
(while (/= Mtext "")
(cond
((wcmatch (strcase (setq Str (substr Mtext 1 2))) "\\[\\{}`~]")
(setq Mtext (substr Mtext 3)
Text (strcat Text Str)
)
)
((wcmatch (substr Mtext 1 1) "[{}]")
(setq Mtext (substr Mtext 2))
)
((and KeepLF (wcmatch (strcase (substr Mtext 1 2)) "\\P"))
(setq Mtext (substr Mtext 3)
Text (strcat Text "\\P")
)
)
((wcmatch (strcase (substr Mtext 1 2)) "\\[LOP]")
(setq Mtext (substr Mtext 3))
)
((wcmatch (strcase (substr Mtext 1 2)) "\\[ACFHQTW]")
(setq Mtext (substr Mtext (+ 2 (vl-string-search ";" Mtext))))
)
((wcmatch (strcase (substr Mtext 1 2)) "\\S")
(setq Str (substr Mtext 3 (- (vl-string-search ";" Mtext) 2))
Text (strcat Text (vl-string-translate "#^\\" " " Str))
Mtext (substr Mtext (+ 4 (strlen Str)))
)
(print Str)
)
(1
(setq Text (strcat Text (substr Mtext 1 1))
Mtext (substr Mtext 2)
)
)
)
)
)
Text
)

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

Scribble

unread,
Apr 2, 2003, 12:18:42 AM4/2/03
to
John,
have you seen:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;;
;; StripMtext v2.1 R15+ Copyright Steve Doman sdo...@yahoo.com 8/25/01
;;
;; Program removes inline formatting from Mtext objects.
;;
;; Call by command:
;; Stripmtext
;;
;; Or call from lisp or script:
;; (StripMtext ss) where ss is a selection set
;;
;; Example to process all mtext objects in drawing from lisp or script:
;; (StripMtext (ssget "x"))


I think I got it from this NG or CFiles?

seems to work pretty well.

cheers
Steve

"John Uhden" <juh...@cadlantic.com> wrote in message
news:6184267E79CB2AD9...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Apr 2, 2003, 12:18:59 AM4/2/03
to
No, I hadn't, Steve. And I had searched all through Google using "Mtext Format"
and variations.
Gotta get to bed, but I'll look for it tomorrow. Thanks.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Scribble" <Scri...@work.now> wrote in message
news:1DCBB384E5112D55...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Apr 2, 2003, 12:25:26 AM4/2/03
to
No, I hadn't, Steve. And I had searched all through Google using "Mtext Format"
and variations.
Gotta get to bed, but I'll look for it tomorrow. Thanks.

--


John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Scribble" <Scri...@work.now> wrote in message
news:1DCBB384E5112D55...@in.WebX.maYIadrTaRb...

Scribble

unread,
Apr 2, 2003, 3:28:29 AM4/2/03
to
John :: found this in my archives :) (thanks go to Steve Doman)

From: "Steve Doman" <sdo...@yahoo.com>
Subject: Removing Mtext formatting StripMtext2.1
Date: Sunday, 26 August 2001 2:53 AM

For anyone that's interested,

Attached is the latest version of my StripMtext routine. Say for
example you have a drawing that contains Mtext objects where the text has
been formatted to override the current textsize, font, color, or whatever.
This program will strip the formatting overrides, allowing the Mtext objects
appearance to revert to its associated textstyle and layer properties.

This version is faster and strips more formatting codes then the previous
version which I posted on the Customization NG on 7/16/01.


"John Uhden" <juh...@cadlantic.com> wrote in message

news:4476866885BD5DB5...@in.WebX.maYIadrTaRb...

StripMtext[2).zip

Tony Tanzillo

unread,
Apr 2, 2003, 8:05:24 AM4/2/03
to

"John Uhden" <juh...@cadlantic.com> wrote in message news:6184267E79CB2AD9...@in.WebX.maYIadrTaRb...
> Having a reason to compare the value of groups of Mtext/Text in an Xref to
> groups of Mtext/Text in the host drawing, I decided to attack the Mtext
> formatting, in hopes of reducing it to a simple string equivalent. Tony said it
> was difficult with AutoLisp, but I hope he was referring only to find *and*
> replace algorithms. While risking public ridicule, I'd appreciate it if you
> sages would test and comment (easy now, Tony).

I'm not sure what's hard about stripping formatting
codes from MTEXT, but what I was referring to is
replacing formatted MTEXT.


Steve Doman

unread,
Apr 12, 2003, 11:12:21 AM4/12/03
to

Your welcome Scribble.

FYI, I am currently working on StripMtext v3.0 The old version will attempt
to remove all formatting from selected mtext. The new version allows the
user to pick which formatting to remove via a dialog box. I am also adding
to v3.0 support for stripping formatting from dimensions mtext, which is
something I overlooked in prior versions (thanks to Joe Burke for
suggesting).

Regards,
Steve Doman


-----

"Scribble" <Scri...@work.now> wrote...

Steve Doman

unread,
Apr 12, 2003, 11:28:22 AM4/12/03
to

Interesting solution John. You might want to add checks for lower case
formatting codes. For example, overline "\O" is sometimes followed by "\o".

Regards,

Steve Doman
-----


"John Uhden" <juh...@cadlantic.com> wrote ...
> ;;========================================================

John Uhden

unread,
Apr 12, 2003, 1:27:06 PM4/12/03
to
I did.

((wcmatch (strcase (substr Mtext 1 2)) "\\[LOP]")

You'd better take another look at your methods, and check out what I just posted
in CF under the subject "StripMtext/Unformat"

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Steve Doman" <sdo...@yahoo.com> wrote in message
news:8CC20A0A3F04E27E...@in.WebX.maYIadrTaRb...

Steve Doman

unread,
Apr 12, 2003, 5:01:45 PM4/12/03
to

John,

I should have read your code more thoroughly, sorry. I was focusing on the
wcmatch argument and didn't see the strcase. I did try your the test you
posted on CF and see what you mean. My code failed to parse the path string
big time.

I guess that's why I'm a drafter and your a programmer. So what should I do
now? Do you want to finish my project? :)

Thanks for the heads up.

Regards,
Steve Doman

------

"John Uhden" <juh...@cadlantic.com> ...

John Uhden

unread,
Apr 12, 2003, 7:00:15 PM4/12/03
to
Here's the deal...
You make the DCL <I hate making them>, and I'll adapt the UnFormat function and
wrap it up into a C:StripMtext or C:UnFormat or both <you pick the name>. Then
we can unleash it as public Doman, er domain. :) I'm not adding all my typical
locked layer detection/options, unless you want to make it a .FAS.

Strip/Unformat Options
x Color x Tracking
x Width x Oblique
x Etc. <yuggh>

o All o Layers o Picklayers o Manually
| OK | | Cancel | | No Help Here |

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Steve Doman" <sdo...@yahoo.com> wrote in message
news:94F6CEA9B9FF3BC4...@in.WebX.maYIadrTaRb...

Steve Doman

unread,
Apr 13, 2003, 12:51:00 PM4/13/03
to

John,

If I try to rewrite my parsing routine to fix the problem that you pointed
out, then it would be difficult to come up with an orignial algorithm after
seeing your clever solution. So although I don't like writing DCL either,
sure I'll do it.

The goal for v3.0 is to allow the user to pick which formatting codes to
remove. That means we need to pass to your Unformat function a textstring
to be unformatted, and some additional arguments that can be used to control
what codes get removed from that textstring.

I suggest something like this:

(unformat
"textsting" ;string to be unformatted
"codes" ;simple codes to be removed
"codes;" ;complex codes with ";" delimiter
bit ;flag to remove hard returns, braces, etc.
)

Also in regards to removing curly braces "{}", that problem becomes much
more complex when not removing all formatting codes, since the codes that
are not to be stripped may be wrapped between braces.

I've handled the locked layer issue in v3.0 by wrapping 'vl-catch-all-apply
around 'vlax-put-property 'textstring. In v3.0, I've added ":L" to the
ssget arguments.

Thanks,

Steve Doman


-----

"John Uhden" <juh...@cadlantic.com> wrote...

John Uhden

unread,
Apr 13, 2003, 2:49:41 PM4/13/03
to
Steve:
For striping options, I'd just use a text string including the desired format
code...
A = Alignment
C = Color
F = Font
H = Height
L = Underline
O = Overscore
P = Linefeed
Q = Obliquing
S = Stacking
T = Tracking (spacing)
W = Width
~ = Non-breaking space

e.g. (StripMtext String "ACHQS~")

The curly brackets are a problem if you want to be a purist; otherwise it's okay
to leave them in.

(vl-catch-all) is a good solution to locked layers and unknown anomalies.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Steve Doman" <sdo...@yahoo.com> wrote in message
news:08B7BA20E7CE1B25...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Apr 13, 2003, 4:20:21 PM4/13/03
to
Hi John,

An off-topic question: the following code uses "1" as the last test
expression in the cond function. I've seen this in some other code you've
posted. Does it operate the same as using "T" in its place, or is there some
subtle distinction?

Command: (cond ((= 1 1) (+ 1 1)) (1 (+ 2 3)))
2

Command: (cond ((= 1 2) (+ 1 1)) (1 (+ 2 3)))
5

Command: (cond ((= 1 2) (+ 1 1)) (T (+ 2 3)))
5

I'm looking forward to whatever you and Steve come up with.

Thanks to both of you...
Joe Burke


"John Uhden" <juh...@cadlantic.com> wrote in message
news:6184267E79CB2AD9...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Apr 13, 2003, 5:02:39 PM4/13/03
to
Joe:

That's an old habit from the days when someone could (setq T nil) whereas
there's no way you could (setq 1 nil). In R15+ I believe that T is a protected
symbol.

I've got the UNFORMAT function working for variable unformatting codes
"ACFHLOPQSTW~" with an optional "*" for everything. Just waiting on Steve to
build a cutesy DCL.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Joe Burke" <job...@hawaii.rr.com> wrote in message
news:9A0DE174D17FB931...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Apr 13, 2003, 5:57:33 PM4/13/03
to
John,

Thanks for the explanation. Looks like there's still reason to use 1 in lieu
of T under A2k2:

Command: (setq T nil)
nil

Command: (cond ((= 1 2) (+ 1 1)) (T (+ 2 3)))

nil

Command: (cond ((= 1 2) (+ 1 1)) (1 (+ 2 3)))
5

Joe Burke

"John Uhden" <juh...@cadlantic.com> wrote in message

news:F83CA64241705089...@in.WebX.maYIadrTaRb...

Doug Broad

unread,
Apr 13, 2003, 6:23:14 PM4/13/03
to
To fix the T = nil problem just issue:
(setq t 't)

"Doug Broad" <dbr...@earthlink.net> wrote in message news:9F0EA47C55FF74C2...@in.WebX.maYIadrTaRb...
> There is no reason to use a test in the last condition if there is
> only one expression in the group...

<snip>


John Uhden

unread,
Apr 13, 2003, 6:57:40 PM4/13/03
to
It's stranger than that...

Command: (setq T nil) nil
Command: (= 1 1) T
Command: (setq OK (= 1 1)) T
Command: (eval ok) nil
Command: !OK T
Command: (if OK (princ "Hello"))
Hello"Hello"
Command: (if T (princ "Hello")) nil

I'll stick to <some of> my old-fashioned methods.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ

"Doug Broad" <dbr...@earthlink.net> wrote in message


news:9F0EA47C55FF74C2...@in.WebX.maYIadrTaRb...
> There is no reason to use a test in the last condition if there is
> only one expression in the group.
>

> I prefer T for readability and for clearly communicating the
> intent. (I would rather track down the misbehaving program
> and berate its author rather than change my program style.
> After all, if someone redefines T, a whole lot else will fail
> besides the last statement of a cond.
>
> What then would this mean with redefined T? (= 1 1)
> The return value would be T which would be nil.....
>
> Using 1 rather than T is quirky and raises more questions
> than it answers.
>
> Just my opinion.
> Regards,
> Doug


>
>
> "Joe Burke" <job...@hawaii.rr.com> wrote in message

news:F532F3508C2A5E39...@in.WebX.maYIadrTaRb...


> > John,
> >
> > Thanks for the explanation. Looks like there's still reason to use 1 in lieu
> > of T under A2k2:
>

> <snip>
>
>

Doug Broad

unread,
Apr 13, 2003, 7:09:58 PM4/13/03
to
<Grin>
Okay dokee. G'nite

Regards,
Doug
Just say (set 't 't)

"John Uhden" <juh...@cadlantic.com> wrote in message news:4F146A429AC68194...@in.WebX.maYIadrTaRb...

> I'll stick to <some of> my old-fashioned methods.
>

<snip>


Scribble

unread,
Apr 14, 2003, 3:06:25 AM4/14/03
to
That'd be very interesting!

I have found your v2.0 handy to remove embedded font types from mtext, which
has been my main need for it.

cheers
Steve

"Steve Doman" <sdo...@yahoo.com> wrote in message

news:E551EFD44C432EF6...@in.WebX.maYIadrTaRb...

Luis Esquivel

unread,
Apr 14, 2003, 10:40:21 AM4/14/03
to
Steve,

I wrote a function to re-color the parts of a mtext, I lefted because the
command that I was going to use still I have some minor problems (this
command is for change the color of simple or nested objects, but I could not
finished yet is now abandon), if you want I can post the function maybe can
be useful.

luis.


Steve Doman

unread,
Apr 14, 2003, 11:12:17 PM4/14/03
to

Ok John, I like that. The DCL is pretty much done but am doing some other
code chores. Will be busy most of the week with drafting. Will get back by
weekend. Lets forget the curly braces for now.

Thanks,
Steve Doman


"John Uhden" <juh...@cadlantic.com> wrote in message

news:78A73271F20FFC6A...@in.WebX.maYIadrTaRb...

Joe Burke

unread,
Apr 15, 2003, 8:21:32 AM4/15/03
to
Steve & John,

I'm not sure what the issue is with curly brackets. Just want to let you
know that's something I added to StripMtext. Sometimes after processing I'd
end up with this {text} in the Properties window. I added strip "\{" "\}"

I also added strip double spaces, convert to single space. I needed that
after adding strip hard returns.

One other thought, which I realize is beyond the intent... *maybe* an option
to let the user strip any character(s) desired? Example: in most cases I've
used StripMtext to fix text received from outside sources. The standard in
the architectural offices where I work is don't use periods in
abbreviations. I get a drawing which needs StripMtext and is full of
abbreviations with periods. It would be nice if I could strip the periods
while massaging the mtext, rather than search and replace as a separate
operation. Just a thought... and maybe not a good one.

Joe Burke

"Steve Doman" <sdo...@yahoo.com> wrote in message

news:5C96BB8BC3B415BB...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Apr 15, 2003, 8:16:40 PM4/15/03
to
Agreed.
The optional "*" format will remove all curly braces used for formatting as
well. Otherwise they are harmless and a subsequent EDIT will discard them.
So include an "All" toggle (hope that makes the number of toggles evenly
spaced).

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"sdoman" <sdo...@yahoo.com> wrote in message news:f1545...@WebX.maYIadrTaRb...
> Joe, It rather easy to remove the curly braces from the entire mtext string.
But much more difficult to strip them if we only want to remove some formatting.
These braces are used by AutoCAD to control the extent of a particular
formatting code. In other words, the braces group together charactes within the
textstring which are to have a specified formatting applied. Sometimes these
braces can be nested rather deep. So we can't just strip all the braces because
that would mess up the displayed formatting of that textstring. I haven't really
given it much thought yet, but perhaps there is a way to remove only the braces
the surround formatting codes that are being removed. If we choose to only
remove some formatting, then I don't see why it would matter to leave braces in,
since you wouldn't normally see them anyhow. If we choose to remove all
formatting, then we could and probably should remove the braces too. As for your
other concerns: I agree that if we are going to strip LineReturns, then we
should add a single space if one is not already there. Replacing other
characters such as "." can be done using AutoCAD's FIND command. So I don't see
that we need to duplicate that feature here. Also this is going to be open
code, so you can tweak it if you so desire. Regards,
> Steve Doman

Joe Burke

unread,
Apr 16, 2003, 10:36:37 AM4/16/03
to
John & Steve,

Agreed. The "All" toggle is my primary concern, if that was in question.

Thanks for the info, Steve.

Joe

"John Uhden" <juh...@cadlantic.com> wrote in message

news:439119203C8CA958...@in.WebX.maYIadrTaRb...

Steve Doman

unread,
Apr 16, 2003, 11:28:33 PM4/16/03
to

Luis,

Sorry I didn't notice your post untill today. If your function removes
Mtext formatting from a textsting, I'd be interested. Otherwise, John
Uhden's function handles the problem very well. Thank you for the offer.

Regards,
Steve Doman


----
"Luis Esquivel" <www.caddximation.com> wrote...

Steve Doman

unread,
Apr 16, 2003, 11:38:39 PM4/16/03
to

John & Joe,

Ok, the DCL now has a "Saveall" & "Clearall" button. If all toggles are
checked, then the program will pass "*" as the search argument to John's
Unformat function. Is that what you were thinking John?

Also added a "Save Settings" toggle for saving the user's prefered default
setting to the Registry.

Anything else?

Steve Doman

"Joe Burke" <job...@hawaii.rr.com> wrote in message

news:3673322B1D89A974...@in.WebX.maYIadrTaRb...

John Uhden

unread,
Apr 17, 2003, 6:39:13 AM4/17/03
to
Good work!
Do you want me to send the updated function to you, or you send the wrapper to
me?

Today you can find me at juh...@vannoteharvey.com
I don't have OE capabilities there.

--
John Uhden, Cadlantic/formerly CADvantage
http://www.cadlantic.com
Sea Girt, NJ


"Steve Doman" <sdo...@yahoo.com> wrote in message
news:887DFBB85DEB5852...@in.WebX.maYIadrTaRb...

Steve Doman

unread,
Apr 18, 2003, 7:20:04 AM4/18/03
to

John,

Please send a copy of your function to sdo...@yahoo.com

I still need to merge the DCL into the wrapper, toss in the registry save
feature, and modify the prompt. I have all this tested and running in bits
and pieces of code here and there. Just have to put dump it all together
and give it a big stir.

Thanks,

Steve Doman

------


"John Uhden" <juh...@cadlantic.com> wrote in message

news:88E40A603C6836FB...@in.WebX.maYIadrTaRb...

0 new messages