如何解析 AutoCAD MText 实体并将其转换为原始文本?

发布于 2024-09-07 08:56:40 字数 645 浏览 10 评论 0原文

我想解析 AutoCAD 的 MText 实体并提取原始文本。我在文本格式中看到了一种模式。如果这个问题已经解决了,那我就不需要重新发明轮子了。我在网上搜索过,但没有找到足够的信息。

我正在寻找有关此主题的任何链接或参考资料。

编辑:

为了进一步澄清,我们正在使用 ODA(开放设计联盟)库来访问 DWG 文件。我对这个图书馆不熟悉。另一位开发人员正在使用该库并从文件中提取信息,包括 MText 实体。然后我会得到一个包含 MText 文本的文件,这就是我正在查看的内容。我正在查看 MText 格式的文本,我可以访问并正在 C# 中使用它。

问题:

  1. 我问另一位开发人员 ODA 库是否提供了提取未格式化的原始文本的方法。他的回答是,这可能会导致实体被写回 DWG 文件。我对原始文本感兴趣,但不影响原始 DWG 文件。 ODA 是否提供了一种在不更改文件的情况下提取原始文本的方法?
  2. 我对任何关于 MText 格式化规则的文档都很感兴趣,这样如果有必要我可以考虑自己编写一个解析器。
  3. 有什么工具可以将 MText 转换为 RTF 吗?我意识到 RTF 不会完全满足所有格式规则,但这可以提供一种在 WinForms 应用程序中显示格式化文本的令人满意的方法。给定 RTF,我还可以获得原始文本。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

北方的巷 2024-09-14 08:56:40

论坛帖子包含一个VB程序来剥离来自 MText 的控制字符。该代码指示应如何去除每个控制字符,因此在 C# 中编写类似的内容应该很简单。

此外,格式代码的文档可在 AutoCAD 文档

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.

稍尽春風 2024-09-14 08:56:40

如果您使用 C# 和 .NET 接口,MText 对象的 Text 属性提供原始文本:

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

如果您还需要格式设置,则解决方案有所不同。

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.

晨光如昨 2024-09-14 08:56:40

如果要在没有 AutoCAD 的情况下解析 AutoCAD 文件,则需要指定要解析的文件类型。但是,这个问题基本上是以下问题的子集:

对于DWG,基本选项是开放设计联盟AutoCAD RealDWG

如果这没有帮助,请提供更多详细信息以说明您正在尝试执行的操作。

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:

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.

二智少女猫性小仙女 2024-09-14 08:56:40

如果您使用 C#,请尝试 netDXF 库。

我认为伪代码应该是这样的:

DxfDocument dxf = new DxfDocument();
dxf = DxfDocument.Load(openFileDialog1.FileName);//load your file
//This extracts the raw text of your first text obj
dxf.MTexts[0].PlainText;

If you are using C#, give the netDXF library a try.

I thought pseudo code should be like this:

DxfDocument dxf = new DxfDocument();
dxf = DxfDocument.Load(openFileDialog1.FileName);//load your file
//This extracts the raw text of your first text obj
dxf.MTexts[0].PlainText;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文