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

Get the string value of MText.Content

8 REPLIES 8
Reply
Message 1 of 9
simonkx
1431 Views, 8 Replies

Get the string value of MText.Content

Hi,
when I got the string value of a MText,it contains TextStyle information such as font、bold、italic and so.Then how can I get the pure value of the MText.Content except the style information.I use C#.
Thanks in advance!
8 REPLIES 8
Message 2 of 9
Anonymous
in reply to: simonkx

Have a look here:

http://www.caddzone.com/MTextFragmentSample.cs

--
http://www.caddzone.com

AcadXTabs: MDI Document Tabs for AutoCAD 2004/2005/2006/2007
http://www.acadxtabs.com

wrote in message news:5136968@discussion.autodesk.com...
Hi,
when I got the string value of a MText,it contains TextStyle information such as font、bold、italic and so.Then how can I get the pure value of the MText.Content except the style information.I use C#.
Thanks in advance!
Message 3 of 9
Anonymous
in reply to: simonkx

It is a sample without any error checking:
[code]
using System;
using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using App = Autodesk.AutoCAD.ApplicationServices.Application;
using EI = Autodesk.AutoCAD.EditorInput;
using ED = Autodesk.AutoCAD.EditorInput.Editor;

[assembly: CommandClass(typeof(ClassLibrary.Class))]

namespace ClassLibrary {
public class Class {
// Define Command "SplitMtext"
[CommandMethod("SplitMtext")]
static public void test() { // This method can have any name
ED ed = App.DocumentManager.MdiActiveDocument.Editor;
EI.PromptEntityResult rs = ed.GetEntity("\nSelect Mtext: ");
if (rs.Status == EI.PromptStatus.OK) {
ObjectId id = rs.ObjectId;
Database db = App.DocumentManager.MdiActiveDocument.Database;
Transaction trans = db.TransactionManager.StartTransaction();
Entity ent = (Entity)trans.GetObject(id, OpenMode.ForRead);
MText mt = ent as MText;
if (mt != null) {
DBObjectCollection dbs = new DBObjectCollection();
mt.Explode(dbs);
string s = "";
foreach (Entity en in dbs) {
DBText txt = en as DBText;
if (txt != null) {
s += txt.TextString;
}
}
ed.WriteMessage("\n" + s); // Print pure Mtext
} else {
ed.WriteMessage("\nIt is not MText entity!");
}
trans.Commit();
}
}
}
}
[/code]
Message 4 of 9
simonkx
in reply to: simonkx

Thank you,Alexander,it really works very well.
Message 5 of 9
Anonymous
in reply to: simonkx

I think that solution by Tony is more universal and elegant, because in next versions of AutoCAD method explode may get text's in other order then now.
It is not documented trick!

Best Regard,
Alexander Rivilis.
Message 6 of 9
vdeprojects44
in reply to: Anonymous

I think that Tony's site isn't anymore and therefore the 'better' solution is gone as well 😞

 


@Anonymous wrote:
I think that solution by Tony is more universal and elegant, because in next versions of AutoCAD method explode may get text's in other order then now. 

 

Message 7 of 9
kdub_nz
in reply to: vdeprojects44


@vdeprojects44 wrote:

I think that Tony's site isn't anymore and therefore the 'better' solution is gone as well 😞

 


@Anonymous wrote:
I think that solution by Tony is more universal and elegant, because in next versions of AutoCAD method explode may get text's in other order then now. 

 


 

Perhaps this:

http://ltc0420.blog.sohu.com/30233215.html

//

Everything will work just as you expect it to, unless your expectations are incorrect.

class keyThumper<T> : Lazy<T>;      another  Swamper

Message 8 of 9
vdeprojects44
in reply to: kdub_nz

Thanks! In the meantime I went with the explode solution as I needed the boundaries of the actual DBText object and not of the overall MText. An alternative is to use the .Text property combined with a Split.

Message 9 of 9
_gile
in reply to: vdeprojects44

Hi,

 

Have a look at the MText.Text property (this property didn't exist yet whrn this post started).



Gilles Chanteau
Programmation AutoCAD LISP/.NET
GileCAD
GitHub

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