views:

151

answers:

3

I would like to parse AutoCAD's MText entity and extract the raw text. I see a pattern in the way the text is formatted. If this has already been solved, then I would not need to reinvent the wheel. I have searched online, but have not found sufficient information.

I am searching for any links or references on this subject.

Edit:

To further clarify, we are using the ODA (Open Design Aliance) libraries to access the DWG files. I am not familiar with this library. Another developer is using the library and extracting information from the files including MText entities. I am then provided with a file containing the MText text, which is what I am looking at. I am looking at the MText formatted text, which I have access to and am working with in C#.

Questions:

  1. I asked the other developer if the ODA library provided a means to extract the raw text unformatted. His response was that it could, however that it would also result in the entity getting written back to the DWG file. I am interested in the raw text without affecting the original DWG file. Does ODA provide a way of extracting the raw text without altering the file?
  2. I am interested in any documentation on the formatting rules of MText, so that I can consider writing a parser myself if necessary.
  3. Is there anything out there to convert MText to RTF? I realize that RTF would not completely satisfy all formatting rules, but this could provide a satisfactory means of displaying the formatted text in a WinForms app. Given RTF I could also obtain the raw text.
A: 

If you are using C# and the .NET interface, the Text property of the MText object provides the raw text:

MText mt;
...
string rawText = mt.Text;

If you want the formatting as well, the solution is different.

Knyphe
This would assume I have a DLL that speaks AutoCAD. I am actually seeking to develop this, so that it can run without having AutoCAD preinstalled. What is the name of this DLL? Does it come with AutoCAD or is it a 3rd party DLL?
Elan
This is using the AutoCAD libraries in AutoCAD. Are you not developing a plugin? If not, you need to specify what kind of file you are parsing the MText from. AutoCAD supports a number of formats. although dwg is the most common, dxf is also a AutoCAD native format.
Knyphe
A: 

If you are parsing an AutoCAD file without AutoCAD, you need to specify what file type you are parsing. However, this question is basically a subset of the following questions:

http://stackoverflow.com/questions/2649181/are-there-any-libraries-for-parsing-autocad-files http://stackoverflow.com/questions/169390/open-source-cad-drawing-dwg-library-in-c/ http://stackoverflow.com/questions/298622/net-cad-component-that-can-read-write-dxf-dwg-files/ http://stackoverflow.com/questions/1000785/reading-dxf-files

For DWG, the basic options are Open Design Alliance and AutoCAD RealDWG.

If this doesn't help, please provide more details as to exactly what you are trying to do.

Knyphe
A: 

This Forum thread includes a VB program to strip the control characters from the MText. The code indicates what should be done to strip each control character, so it should be straightforward to write something similar in C#.

Additionally, the documentation of the format codes is available in the AutoCAD documentation.

Knyphe