如何解析 AutoCAD MText 实体并将其转换为原始文本?
我想解析 AutoCAD 的 MText 实体并提取原始文本。我在文本格式中看到了一种模式。如果这个问题已经解决了,那我就不需要重新发明轮子了。我在网上搜索过,但没有找到足够的信息。
我正在寻找有关此主题的任何链接或参考资料。
编辑:
为了进一步澄清,我们正在使用 ODA(开放设计联盟)库来访问 DWG 文件。我对这个图书馆不熟悉。另一位开发人员正在使用该库并从文件中提取信息,包括 MText 实体。然后我会得到一个包含 MText 文本的文件,这就是我正在查看的内容。我正在查看 MText 格式的文本,我可以访问并正在 C# 中使用它。
问题:
- 我问另一位开发人员 ODA 库是否提供了提取未格式化的原始文本的方法。他的回答是,这可能会导致实体被写回 DWG 文件。我对原始文本感兴趣,但不影响原始 DWG 文件。 ODA 是否提供了一种在不更改文件的情况下提取原始文本的方法?
- 我对任何关于 MText 格式化规则的文档都很感兴趣,这样如果有必要我可以考虑自己编写一个解析器。
- 有什么工具可以将 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:
- 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?
- I am interested in any documentation on the formatting rules of MText, so that I can consider writing a parser myself if necessary.
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
此论坛帖子包含一个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.
如果您使用 C# 和 .NET 接口,MText 对象的 Text 属性提供原始文本:
如果您还需要格式设置,则解决方案有所不同。
If you are using C# and the .NET interface, the Text property of the MText object provides the raw text:
If you want the formatting as well, the solution is different.
如果要在没有 AutoCAD 的情况下解析 AutoCAD 文件,则需要指定要解析的文件类型。但是,这个问题基本上是以下问题的子集:
是否有用于解析 AutoCAD 文件的库?
C# 中的开源 cad 绘图 (dwg) 库
.Net CAD组件,可以读取/写入dxf/dwg文件
读取 .DXF 文件
对于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:
Are there any libraries for parsing AutoCAD files?
Open source cad drawing (dwg) library in C#
.Net CAD component that can read/write dxf/ dwg files
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.
如果您使用 C#,请尝试 netDXF 库。
我认为伪代码应该是这样的:
If you are using C#, give the netDXF library a try.
I thought pseudo code should be like this: