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
8449 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 21 of 42
WM_Ron_Allen
in reply to: Anonymous

I swore having dealt with this so many years when I had a better mousetrap I would post the code:

So the Code (Below?) substituted with REGEX:

 

Attribute VB_Name = "ACAD_TEXT"
''AutoCAD VBA 2010
''Routine to strip formatting in ALL Autocad MTEXT (Translating Revit
''"text" to autocad drawings dumps as MTEXT with some odd formatting
''issues) try this:
Option Explicit
Sub Make_Mtext_StyleDependant()
   Dim oAcadObj As AcadObject
   
   Dim ObjBlock As AcadBlock
   Dim ObjBlocks As AcadBlockReference
   
   Dim ObjTxt As AcadMText

   Dim ObjAcad As AcadObject
   
   Dim x
   
   Dim re As New RegExp
   
   Set re = CreateObject("VBScript.RegExp")
   
   For Each ObjBlock In ThisDrawing.Blocks
   If InStr(1, LCase(ObjBlock.Name), "seal") < 1 Then ''don't mess with the seals!
   For Each ObjAcad In ObjBlock
      If InStr(1, LCase(ObjAcad.ObjectName), "mtext") > 0 Then
         Set ObjTxt = ObjAcad
         x = UnformatMtext(ObjTxt.TextString)
         ObjTxt.TextString = x 
      End If
   Next ObjAcad
   End If
   Next ObjBlock
End Sub

Function ReReplace(str As String, pat As String, repl As String) As String
Dim re As New RegExp
Dim Found As Boolean
Set re = CreateObject("VBScript.RegExp")
  re.IgnoreCase = False
  re.Pattern = pat
  re.Global = True

  Found = re.Test(str)

ReReplace = re.Replace(str, repl)
End Function

Function UnformatMtext(S As String) As String
   ''https://forums.autodesk.com/t5/visual-basic-customization/mtext-format-codes/td-p/356713
   Dim P1 As Integer
   Dim P2 As Integer, P3 As Integer
   Dim intStart As Integer
   Dim strCom As String
   Dim strReplace As String
   
   S = ReReplace(S, "\\A[012]\;", "")
   S = ReReplace(S, "\%\%P", "+or-")
   S = ReReplace(S, "\%\%D", "+or-")
   S = ReReplace(S, "\\P", Chr(10))
   S = ReReplace(S, "\\[ACfFQTWHp].*?\;", "")
   S = ReReplace(S, "\\[LO].*\;", "")
   S = ReReplace(S, "\\[S](.*?)\;", "$1")
   S = ReReplace(S, "\\U2248", "ALMOST EQUAL")
   S = ReReplace(S, "\\U2220", "ANGLE")
   S = ReReplace(S, "\\U2104", "CENTER LINE")
   S = ReReplace(S, "\\U0394", "DELTA")
   S = ReReplace(S, "\\U0278", "ELECTRIC PHASE")
   S = ReReplace(S, "\\UE101", "FLOW LINE")
   S = ReReplace(S, "\\U2261", "IDENTITY")
   S = ReReplace(S, "\\UE200", "INITIAL LENGTH")
   S = ReReplace(S, "\\UE102", "MONUMENT LINE")
   S = ReReplace(S, "\\U2260", "NOT EQUAL")
   S = ReReplace(S, "\\U2126", "OHM")
   S = ReReplace(S, "\\U03A9", "OMEGA")
   S = ReReplace(S, "\\U214A", "PROPERTY LINE")
   S = ReReplace(S, "\\U2082", "SUBSCRIPT2")
   S = ReReplace(S, "\\U00B2", "SQUARED")
   S = ReReplace(S, "\\U00B3", "CUBED")
   S = Replace(S, "\\\~", " ")
   S = Replace(S, "\\", "\")
   UnformatMtext = S

End Function

 

Ron Allen
Ware Malcomb Bim
Message 22 of 42
Anonymous
in reply to: Anonymous

Thank you terry very much for this helpful post

Message 23 of 42
BhaskarMurari
in reply to: Anonymous

\fhelvetica lt com|b1|i0|c0|p2|;\W.8;?

Hi can someone help whats that context 

Thanks 

Message 24 of 42
Ed.Jobe
in reply to: BhaskarMurari

You can find a list of the format codes here.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 25 of 42
BhaskarMurari
in reply to: Ed.Jobe

the issue with a specific drawings. The text displays as "?"  can't show properly inside the cloud in the attached drawing,

Tried installing the font still the issue persists.

tried the steps from the below knowledge base article, but still issue persists

  1. Text objects use a different font than expected in AutoCAD
  2. MText objects do not honor Text Styles in AutoCAD
  3. "One or more SHX files are missing. What would you like to do?" when opening a drawing in AutoCAD Pr...

I also installed the online-downloaded font that is below, but unfortunately this did not prevent the text from displaying "? " The font is attached for your reference.

 

Attaching the drawing file ,, please someone look into drawing and give me solution, whats inside that cloud with "?"

Thank you in advance

Message 26 of 42
Ed.Jobe
in reply to: BhaskarMurari

There's a missing xref that looks like it was from a Revit title block. So I would say that the Revit user used some codes that did not translate to AutoCAD or they used a character in a special font that is not present in the fonts that are currently used in the dwg. Or they literally used a ?. Anyway, from the dwg you sent, it's impossible to tell now. You would have to contact the original creator to find out what it is supposed to be. I didn't get any missing font errors, so maybe if you sent the file you got I could tell.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 27 of 42
BhaskarMurari
in reply to: Ed.Jobe

Thank you @Ed.Jobe for the insights on this.  But the sources where I received the  only this drawings. Also I don't have any other xref with me. Please let me know Is  there a way to get rid of this error. I have tried all the above steps from knowledge articles I have shared in my original post. Thank you again for looking into the drawings.

Message 28 of 42
Ed.Jobe
in reply to: BhaskarMurari

Can you post the original dwg so that I can get the same error? I did not get any errors with the file you posted. I can't duplicate your problem, so at this point, all I can say is that the information is missing.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 29 of 42
BhaskarMurari
in reply to: Ed.Jobe

I cannot share the drawings on the public channel due to privacy and confidentiality concern. I'm really sorry for this. Please if you other alternates kindly suggest me.

Message 30 of 42
Ed.Jobe
in reply to: BhaskarMurari

If you edit the mtext and select all the contents, then right click and select Remove All Formatting, you will see that the contents are just a "?". You are missing information. It's possible that it was that way in the original Revit file. Drafters sometimes copy text that way, intending to come back and fix it later when they know what to use.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 31 of 42
BhaskarMurari
in reply to: Ed.Jobe

Thank you for very quick response. @Ed.Jobe 

Exactly after removing formatting I still get "?".  The original revit file may carry the missing information. Also with that revit file we cannot come an conclusion what's that content available.  Is that correct @Ed.Jobe .please confirm.

 

Thank you @Ed.Jobe  for your valuable inputs. 

 

Message 32 of 42
Ed.Jobe
in reply to: BhaskarMurari

Yes, that's what I was saying. You need to look at the original file, even a pdf will do.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 33 of 42
BhaskarMurari
in reply to: Ed.Jobe

Thank you for re confirmation @Ed.Jobe . The sources I obtained the drawings are not ready to share any other information for me. This making to annoy a lot. But I still insists my sources to get pdf or revit drawings and check with it. Thank you for valuable feedback. Plea

Message 34 of 42

It may be a special font or your font substitution file doesn't account for that font as well!

Ron Allen
Ware Malcomb Bim
Message 35 of 42
Ed.Jobe
in reply to: WM_Ron_Allen

@WM_Ron_Allen Thanks, but I checked for that. Either the original Revit file contents was a "?" or the info was lost during export to dwg due to missing font/etc. The font specified in this uploaded file is just Helvetica.

 

@BhaskarMurari  One of the texts has mtext formatting codes applied to the context, referencing time.shx. This is a standard font that ships with AutoCAD. If your pc was missing this font file, that would explain why you got errors. The rest of the fonts used by this file are Windows standard ttf files.

Ed


Did you find this post helpful? Feel free to Like this post.
Did your question get successfully answered? Then click on the ACCEPT SOLUTION button.
How to post your code.

EESignature

Message 36 of 42
WM_Ron_Allen
in reply to: Anonymous

Try Arial - it is the most ubiquitous font followed by arial MT(The only font that shows up in schedules, text, tags, symbols) in revit and Autocad correctly. Also check the font substitute is available. 

 

I suspect if you do a test with a sheet converted to arial the issue will subside.

Ron Allen
Ware Malcomb Bim
Message 37 of 42

Thank you  @WM_Ron_Allen , I have changed to each and every font and font style available in AutoCAD, and also  copied the drawings to new sheet and tested , what ever I do I ended with "?" .

Message 38 of 42

@BhaskarMurari  this may help. Note you may see formatting from the external editor as well. This may be picked up or ignored- guessing on the styles between the "|" Symbols...


RonAllen_WareMalcombcom_0-1665071177206.png

@Ed.Jobe - the Autodesk reference is incomplete. The original mtext editor substituted those common codes with text for that reason : )

 

If you want to maintain consistency - I suggest turning off the external editor, using Autocad mtext out of the box, and if you have heavy formatting in text/documents; convert the text from E.G. Word to images or PDFs to link into pages to maintain sheets with heavy formatting.

Ron Allen
Ware Malcomb Bim
Message 39 of 42

A font defined in the inline Mtext is the most likely culprit. Stripping those out will do the trick.

 

One VBA I recall used a rich text box in a form to post and copy back from to break it back to the basic Bold/Italic/Underline and I think numbered and bullet lists.

Ron Allen
Ware Malcomb Bim
Message 40 of 42

Thank you @WM_Ron_Allen Please let me know how to do that trick. I am not aware of VB

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

Post to forums  

Autodesk Design & Make Report

”Boost