Active Contributor
35 Posts
1 Kudo
Registered: ‎08-30-2010
Post 1 of 4

MText Formatting Codes to vb String

651 Views, 3 Replies
10-16-2012 12:00 PM

I am lifting mtext from a drawing and then working with the result.  For some reason the "\\pxi-" at the begining of the string I am lifting is converting to "\ pxi-" when worked with as a string in vb.net.  The result is this, when I apply the string back to mtext I get a bunch of messed up formatting codes at the begining rather than a formatted piece of text.


This seems to be related to the "\\" Is this automatically getting modified by vb or autocad when I pull the source text?



*Expert Elite*
1,569 Posts
171 Kudos
Registered: ‎10-08-2008
Post 2 of 4

Re: MText Formatting Codes to vb String

10-16-2012 11:35 PM in reply to: JasonSelf

Add to directives region:          

Imports System.Text.RegularExpressions          

then split string using Regex or usual way  

using String.Replace


Dim str AsString = Regex.Split("\pxi;here is your mtext string...", ";")(1)

this will cut your formatting prefix

Valued Mentor
340 Posts
53 Kudos
Registered: ‎05-12-2009
Post 3 of 4

Re: MText Formatting Codes to vb String

10-17-2012 04:31 AM in reply to: Hallex

Unless it is formatted with fonts, etc.... which most people dislike and reason for this method, but for basic formatting you can use the Mtext.Text property modify then set it to the MText.Contents property.


Here is a litte one converted to VB that gets rid of all font and size formatting but will keep all 'returns', it has some extensions method used but easy to tell what it is doing.


Public Sub STRIPMTXT()
	Using trx As Transaction = Db.TransactionManager.StartTransaction()
		Dim btr As BlockTableRecord = Db.CurrentSpace()
		Dim mtxts = btr.GetObjectsOfType(Of MText)(OpenMode.ForWrite)

		For Each mtxt As MText In mtxts
			mtxt.Contents = mtxt.Text

	End Using

End Sub




You can also find your answers @ TheSwamp
Active Contributor
35 Posts
1 Kudo
Registered: ‎08-30-2010
Post 4 of 4

Re: MText Formatting Codes to vb String

10-17-2012 05:09 AM in reply to: JasonSelf

Thanks for your help guys....Jeff I think I'm going to go with your plan, although I was kinda hoping I could easily maintain the formatting codes.  After I get this round of programing done I will probably modify it to do the regex split and then put the formatting back when I am done working with the text, if that is possible due to the double backslash issue.



Post to the Community

Have questions about Autodesk products? Ask the community.

New Post