i.e.
myText.Contents = "First line \\P Second line";
I want to get all MText values such as "First line Second line" ;
However, my codes get the value has newline;
"First line
Second line"
public string GetAllMText() { string test = string.Empty; Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument; Database db = doc.Database; Editor ed = doc.Editor; TypedValue[] filter = { new TypedValue(0, "MTEXT"), new TypedValue(8, "0") }; PromptSelectionResult psr = ed.SelectAll(new SelectionFilter(filter)); if (psr.Status == PromptStatus.OK) { List<string> values = new List<string>(); using (Transaction tr = db.TransactionManager.StartTransaction()) { foreach (ObjectId id in psr.Value.GetObjectIds()) { MText text = (MText)tr.GetObject(id, OpenMode.ForRead); values.Add(text.Text.ToString()); } tr.Commit(); } foreach (string eachString in values) { test += eachString; } } return test; }
Might I have your kind help, your help would be greatly appreciated.
Solved! Go to Solution.
Solved by CADbloke. Go to Solution.
Solved by CADbloke. Go to Solution.
You want the .Contents of the MText. Instead of
values.Add(text.Text.ToString();
use
values.Add(text.Contents);
It is already a string to the ToString() call is redundant. Download the SDK for the version you are using and peruse the arxmgd.chm guide, search for MText Properties.
No, I want to get the value is "First line Second line", not "First line \\P Second line"
if use
values.Add(text.Contents);
get the value is "First line \\P Second line"
You're right - sorry, I had .Text & .Contents mixed up.
You can replace the carriage return with a space (if you need the extra space). See http://stackoverflow.com/a/238020/492
values.Add(text.Text.Replace(System.Environment.NewLine, " "));
Aaaah, wait, I'm close (I'll leave that here in case it's useful to someone but it's wrong for this exercise), you want
values.Add(text.Text.Replace(@"\\P", " "));
Here is a list of the formatting codes you are likely to come across in MText : http://www.cadforum.cz/cadforum_en/text-formatting-codes-in-mtext-objects-tip8640
I Hope this is more useful than my wrong answer.