.NET

Reply
Active Contributor
JasonSelf
Posts: 35
Registered: ‎08-30-2010
Message 1 of 4 (540 Views)

MText Formatting Codes to vb String

540 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?

 

Thanks,
Jason

*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 2 of 4 (513 Views)

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

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
Valued Mentor
jeff
Posts: 330
Registered: ‎05-12-2009
Message 3 of 4 (505 Views)

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
		Next

		trx.Commit()
	End Using

End Sub

 

 

 

You can also find your answers @ TheSwamp
Active Contributor
JasonSelf
Posts: 35
Registered: ‎08-30-2010
Message 4 of 4 (502 Views)

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.

 

Thanks,
Jason

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.
Need installation help?

Start with some of our most frequented solutions or visit the Installation and Licensing Forum to get help installing your software.