.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

MText Formatting Codes to vb String

3 REPLIES 3
Reply
Message 1 of 4
JasonSelf
1468 Views, 3 Replies

MText Formatting Codes to vb String

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

3 REPLIES 3
Message 2 of 4
Hallex
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
Message 3 of 4
jeff
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
Message 4 of 4
JasonSelf
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

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

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost