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

Newline problem in MText ?

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
Jyh2003
2430 Views, 4 Replies

Newline problem in MText ?

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.

 

 

4 REPLIES 4
Message 2 of 5
CADbloke
in reply to: Jyh2003

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.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 3 of 5
Jyh2003
in reply to: CADbloke

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"

Message 4 of 5
CADbloke
in reply to: Jyh2003

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.

- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com
Message 5 of 5
CADbloke
in reply to: CADbloke

I hate this forum software (can't edit my answer). ok, my first line of code will work on MText.Text, the second line of code will work on MText.Contents but you probably already figured that out.
- - - - - - -
working on all sorts of things including www.tvCAD.tv & www.CADreplace.com

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