VBA
Discuss AutoCAD ActiveX and VBA (Visual Basic for Applications) questions here.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MTEXT FORMAT CODES!?!?!

41 REPLIES 41
Reply
Message 1 of 42
Anonymous
9081 Views, 41 Replies

MTEXT FORMAT CODES!?!?!

I need to parse the .TextString from an MText object.
However, im having a time trying to find a list of the formatting
codes for mtext.. The link in my help file is not working..
Can anyone help me please??

-Andrew
41 REPLIES 41
Message 2 of 42
Anonymous
in reply to: Anonymous

Are you saying you want to remove all formatting codes
from the TextString ? (hmmm, kinda makes you wonder if
they should even be there to begin with) ?

"Andrew Allen" wrote in message
news:4D179E5DBB2899DCF0DDE68611F16339@in.WebX.maYIadrTaRb...
> I need to parse the .TextString from an MText object.
> However, im having a time trying to find a list of the
formatting
> codes for mtext.. The link in my help file is not working..
> Can anyone help me please??
>
> -Andrew
>
>
Message 3 of 42
Anonymous
in reply to: Anonymous

GOOD POINT!! Lets complain to AutoDesk. MTEXT is a big fat mess!!
HELP ME!!!
Message 4 of 42
Anonymous
in reply to: Anonymous

Andrew Allen wrote:
 
> I need to parse the .TextString from an MText object.
> However, im having a time trying to find a list of the formatting
> codes for mtext.. The link in my help file is not working..

It worked well in the R14 help file ...

\0...\o Turns overline on and off
\L...\l Turns underline on and off
\~ Inserts a nonbreaking space
\\ Inserts a backslash
\{...\} Inserts an opening and closing brace
\Cvalue; Changes to the specified color
\File name; Changes to the specified font file
\Hvalue; Changes to the specified text height
\Hvaluex; Changes to multiple of mtext object's property
\S...^...; Stacks the subsequent text at the \ or ^ symbol
\Tvalue; Adjusts the space between characters
\Qangle; Changes obliquing angle
\Wvalue; Changes width factor to produce wide text
\A Sets the alignment value; valid values: 0, 1, 2 (bottom,
center, top)
\P Ends paragraph

Good Luck, Terry
Message 5 of 42
Anonymous
in reply to: Anonymous

Thank you terry, that is helpful..
Call me a lazy (edited), but i am hoping someone has already made a function
to strip out all the (edited), and produce an actual text string, minus the
format flags.
Do you, or anyone.. have such a function. I could write it, splitting on
all backslashes,.. but like i said, if its already done somewehre, i would
appreciate the snippet.
THANK YOU!!
-andrew
Message 6 of 42
Anonymous
in reply to: Anonymous

Well - Autodesk apparently didn't have the wisdom to forsee
a need for a 'PlainText' property (text without formatting
information, kind of like what you get from the innerText
property of an HTML element).

I was going to suggest copying to the clipboard, but a quick
test reveals that even more absurd, copying MTEXT to the
clipboard, does not render it in CF_TEXT or Rich text format.

Strangely, it does get rendered in CF_TEXT if you copy it
from the MTEXT editor.

Can I ask what you need the un-formatted text for?
Message 7 of 42
Anonymous
in reply to: Anonymous

Andrew Allen wrote:

> Call me a lazy (edited), but i am hoping someone has already made a function
> to strip out all the (edited), and produce an actual text string, minus the
> format flags.

I saw one once in LSP by Steve Doman, you may search google groups for
it.

Terry
Message 8 of 42
Anonymous
in reply to: Anonymous

Tony,
I am writing a script to mass process many directories of many old drawings.
This script will standardize the lot of them. In THIS particular case, i
want to take whatever text is there, whether it be MText or Regular text and
get its contents, then recreate it in regular, standard text format.
-Andrew

"Tony Tanzillo" wrote in message
news:CF7F481CE8811575171F07F714869DED@in.WebX.maYIadrTaRb...
> Well - Autodesk apparently didn't have the wisdom to forsee
> a need for a 'PlainText' property (text without formatting
> information, kind of like what you get from the innerText
> property of an HTML element).
>
> I was going to suggest copying to the clipboard, but a quick
> test reveals that even more absurd, copying MTEXT to the
> clipboard, does not render it in CF_TEXT or Rich text format.
>
> Strangely, it does get rendered in CF_TEXT if you copy it
> from the MTEXT editor.
>
> Can I ask what you need the un-formatted text for?
>
>
>
>
>
Message 9 of 42
Anonymous
in reply to: Anonymous

Andrew Allen wrote:

> Call me a lazy (edited), but i am hoping someone has already made a function

Take a look at the discussion over in .drafting called " Importing text
files into Autocad", including Steve's routine.

Terry
Message 10 of 42
Anonymous
in reply to: Anonymous

I have built a VB Function that works. It does the job, however i cant
garantee that it will catch EVERY formatting code in an MTExt window.. I
would be happy to mail it to anyone interested.

Thank you everyone

-Andrew

"Andrew Allen" wrote in message
news:4D179E5DBB2899DCF0DDE68611F16339@in.WebX.maYIadrTaRb...
> I need to parse the .TextString from an MText object.
> However, im having a (edited) of a time trying to find a list of the
formatting
> codes for mtext.. The link in my help file is not working..
> Can anyone help me please??
>
> -Andrew
>
>
Message 11 of 42
Anonymous
in reply to: Anonymous

Can I assume that by this you mean you want to convert
all existing MTEXT objects into one or more TEXT objects?

If you're processing the drawings using a script, you can
use the EXPLODE command to explode existing MTEXT entities
into standard text, with the caveat that the resulting text
is 'fragmented' by formatting changes, in addition to line
breaks.

"Andrew Allen" wrote in message
news:7C8575893EAF6087C6CC16D62298CCC7@in.WebX.maYIadrTaRb...
> Tony,
> I am writing a script to mass process many directories of many old
drawings.
> This script will standardize the lot of them. In THIS particular case, i
> want to take whatever text is there, whether it be MText or Regular text
and
> get its contents, then recreate it in regular, standard text format.
> -Andrew
>
> "Tony Tanzillo" wrote in message
> news:CF7F481CE8811575171F07F714869DED@in.WebX.maYIadrTaRb...
> > Well - Autodesk apparently didn't have the wisdom to forsee
> > a need for a 'PlainText' property (text without formatting
> > information, kind of like what you get from the innerText
> > property of an HTML element).
> >
> > I was going to suggest copying to the clipboard, but a quick
> > test reveals that even more absurd, copying MTEXT to the
> > clipboard, does not render it in CF_TEXT or Rich text format.
> >
> > Strangely, it does get rendered in CF_TEXT if you copy it
> > from the MTEXT editor.
> >
> > Can I ask what you need the un-formatted text for?
> >
> >
> >
> >
> >
>
>
Message 12 of 42
Anonymous
in reply to: Anonymous

Andrew,

Could I get that mtext code removing VB Function?

David
Message 13 of 42
Anonymous
in reply to: Anonymous

Good point, who knows what you've missed. I have all I could find in here
[code]
Function UnformatMtext(S As String) As String

Dim P1 As Integer
Dim P2 As Integer, P3 As Integer
Dim intStart As Integer
Dim strCom As String
Dim strReplace As String

Debug.Print S

Select Case Left(S, 4)
Case "\A0;", "\A1;", "\A2;"
S = Mid(S, P1 + 5)
End Select
intStart = 1
Do
P1 = InStr(S, "%%")
If P1 = 0 Then
Exit Do
Else
Select Case Mid(S, P1 + 2, 1)
Case "P"
S = Replace(S, "%%P", "+or-")
Case "D"
S = Replace(S, "%%D", " deg")
End Select
End If
Loop

Do
P1 = InStr(intStart, S, "\", vbTextCompare)
If P1 = 0 Then Exit Do
strCom = Mid(S, P1, 2)
Select Case strCom
Case "\p"
P2 = InStr(1, S, ";")
S = Mid(S, P2 + 1)
Case "\A", "\C", "\f", "\F", "\H", "\Q", "\T", "\W"
P2 = InStr(P1 + 2, S, ";", vbTextCompare)
P3 = InStr(P1 + 2, S, strCom, vbTextCompare)
If P3 = 0 Then
S = Left(S, P1 - 1) & Mid(S, P2 + 1)
End If
Do While P3 > 0
P2 = InStr(P3, S, ";", vbTextCompare)
S = Left(S, P3 - 1) & Mid(S, P2 + 1)
'Debug.Print s, strCom
P3 = InStr(1, S, strCom, vbTextCompare)
Loop
's = Left(s, P3 - 1) & mid(s, P3 + 1)
Case "\L", "\O"
Dim strLittle As String
strLittle = LCase(strCom)
P2 = InStr(P1 + 2, S, strLittle, vbTextCompare)
S = Left(S, P1 - 1) & Mid(S, P1 + 2, P2 - (P1 + 2)) & Mid(S, P2 + 2)
Case "\S"
P2 = InStr(P1 + 2, S, ";", vbTextCompare)
P3 = InStr(P1 + 2, S, "/", vbTextCompare)
If P3 = 0 Or P3 > P2 Then
P3 = InStr(P1 + 2, S, "#", vbTextCompare)
End If
If P3 = 0 Or P3 > P2 Then
P3 = InStr(P1 + 2, S, "^", vbTextCompare)
End If
S = Left(S, P1 - 1) & Mid(S, P1 + 2, P3 - (P1 + 2)) _
& "/" & Mid(S, P3 + 1, (P2) - (P3 + 1)) & Mid(S, P2 + 1)

Case "\U"
strLittle = Mid(S, P1 + 3, 4)
Debug.Print strLittle
Select Case strLittle
Case "2248"
strReplace = "ALMOST EQUAL"
Case "2220"
strReplace = "ANGLE"
Case "2104"
strReplace = "CENTER LINE"
Case "0394"
strReplace = "DELTA"
Case "0278"
strReplace = "ELECTRIC PHASE"
Case "E101"
strReplace = "FLOW LINE"
Case "2261"
strReplace = "IDENTITY"
Case "E200"
strReplace = "INITIAL LENGTH"
Case "E102"
strReplace = "MONUMENT LINE"
Case "2260"
strReplace = "NOT EQUAL"
Case "2126"
strReplace = "OHM"
Case "03A9"
strReplace = "OMEGA"
Case "214A"
strReplace = "PROPERTY LINE"
Case "2082"
strReplace = "SUBSCRIPT2"
Case "00B2"
strReplace = "SQUARED"
Case "00B3"
strReplace = "CUBED"

End Select
S = Replace(S, "\U+" & strLittle, strReplace)

Case "\~"
S = Replace(S, "\~", " ")

Case "\\"
intStart = P1 + 2
S = Replace(S, "\\", "\")
GoTo Selectagain

Case "\P"
intStart = P1 + 1
GoTo Selectagain
Case Else
Exit Do
End Select
Selectagain:
Loop

Do
P1 = InStr(1, S, "\P", vbTextCompare)
If P1 = 0 Then
Exit Do
Else
S = Left(S, P1 - 1) & vbCrLf & Mid(S, P1 + 2)
End If
Loop
For intStart = 0 To 1
If intStart = 0 Then
strCom = "}"
Else
strCom = "{"
End If
P2 = InStr(1, S, strCom)

Do While P2 > 0
S = Left(S, P2 - 1) & Mid(S, P2 + 1)
P2 = InStr(1, S, strCom)
Loop
Next intStart


UnformatMtext = S

End Function

Sub Testmt()
Dim Mt As AcadMText, V As Variant
ThisDrawing.Utility.GetEntity Mt, V, "Pick an Mtext:"
Debug.Print Mt.TextString
Mt.TextString = UnformatMtext(Mt.TextString)
Debug.Print Mt.TextString
End Sub
[/code]
Message 14 of 42
Anonymous
in reply to: Anonymous

I would like to take your code and try to apply it to an AutoCAD Table. In other words remove mtext formatting codes in a Acad table. But my VBA skills are not that good, so before I tackle that has anybody already created a prog to get rid of formatting codes of a table?

Eric
Message 15 of 42
Anonymous
in reply to: Anonymous

I've tried it with regexp - but it's hard;-)
Anyway, a test and just for fun, its friday ...

my mtext.textstring look's at first:

{\fArial|b0|i1|c0|p34;zeile1}\P{\fArial Narrow|b1|i0|c0|p34;\C2;zeile2\P\fBauhaus 93|b0|i0|c0|p82;\H2x;\L\C256;zeile3\P\fArial|b0|i0|c0|p34;\H0.5x;zeile4}

and at last:

zeile1\Pzeile2\Pzeile3\Pzeile4

I don't know, if i've taken all possibilities,
it's just a careful step along the stony mText-way.

'****************************************************************
Sub regexTest()
Dim sset As AcadSelectionSet, ent As AcadEntity, re As Object
Set sset = ActiveDocument.SelectionSets.Add("set2")
sset.SelectOnScreen
Set re = CreateObject("vbscript.regexp")
re.IgnoreCase = 1: re.Global = 1: re.MultiLine = 0

re.Pattern = "\{?(?:\\[fHLC].*?;|\}).*?(.*?)"

For Each ent In sset
If TypeOf ent Is IAcadMText Then
Debug.Print ent.TextString
ent.TextString = re.Replace(ent.TextString, "$1")
Debug.Print ent.TextString
End If
Next
sset.Delete
Set re = Nothing
End Sub
'****************************************************************

BTW, some hint's are welcome 🙂

cu trekkie
Message 16 of 42
Anonymous
in reply to: Anonymous

Thanks for sharing this function. It was crashing for me on underlined text that had the starting \L but was underlined till the end and didn't have the ending \l. For example this mtext string:

{\fArial|b1|i0|c0|p34;\LGENERAL NOTES :}

I fixed it by slightly changing the case for \L as follows:

Case "\L", "\O"
Dim strLittle As String
strLittle = LCase(strCom)
P2 = InStr(P1 + 2, S, strLittle, vbTextCompare)
If P2 = 0 Then
S = Left(S, P1 - 1) & Mid(S, P1 + 2)
Else
S = Left(S, P1 - 1) & Mid(S, P1 + 2, P2 - (P1 + 2)) & Mid(S, P2 + 2)
End If
Message 17 of 42
Anonymous
in reply to: Anonymous

Thanks for posting the fix.
Message 18 of 42
harryliu3140
in reply to: Anonymous

Thank you all for your contribution. I'm really benefited from this forum.
Message 19 of 42
Anonymous
in reply to: Anonymous

Hi Out There,

I was wondering after reading the tread on MText with interest, if there was any code for changing String Text to MText and then to copy the MText into a table and then export to Excel.

Regards,

Jeremy
Message 20 of 42
Anonymous
in reply to: Anonymous

This can be accomplished with regex.  Just implement the code to remove any matches.  

 

\\[A-Za-z0-9.\/\#\^]+;

 

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

Post to forums  

Technology Administrators


Autodesk Design & Make Report