MText Formatting Codes to vb String

MText Formatting Codes to vb String

Anonymous
Not applicable
2,128 Views
3 Replies
Message 1 of 4

MText Formatting Codes to vb String

Anonymous
Not applicable

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?

 

Thanks,
Jason

0 Likes
2,129 Views
3 Replies
Replies (3)
Message 2 of 4

Hallex
Advisor
Advisor

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

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 3 of 4

jeff
Collaborator
Collaborator

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
		Next

		trx.Commit()
	End Using

End Sub

 

 

 

You can also find your answers @ TheSwamp
0 Likes
Message 4 of 4

Anonymous
Not applicable

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.

 

Thanks,
Jason

0 Likes