如何解码 .dxf 文件? [英] How to decode .dxf files?

查看:38
本文介绍了如何解码 .dxf 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将 .dxf 文件中的图纸转换为 g 代码.有一些工具可以做到这一点,但我想自己编写代码.所以,第一部分是解码 .dxf 格式.然而,.dxf 文件的内容看起来并不容易破译.

我在此处下载了一个 .dxf 文件并在文本编辑器中打开它.

我还指的是这个手册.看起来 .dxf 文件中的内容主要是样式和配置信息,我倾向于忽略几乎所有内容.所以,1.如果有的话,你能指定不应省略的属性吗?

据我所知,这些数字在 .dxf 文件中分为多个实体.因此,我只是复制粘贴实体部分.请注意,文件中有 6 个 SECTIONS,最后一个部分(BLOCKS OBJECTS)是最长的一个,尽管我不知道那部分代表什么(如果您能解释一下就好了).

在下面的代码中,10 和 20 应该代表 X 和 Y 位置,42 应该代表凸起.跟踪折线是可能的.我考虑通过使用 TITLES 作为导航点以及 10、20 和 42 等数字从文件中提取信息.但下面有两条折线.所以,2.我应该考虑哪条折线,另一条的用途是什么?

<代码> 0部分2实体0折线572#什么330#是1F#这些100#号码?实体8第一层100AcDb折线901270143 # 等宽(可选;默认 = 0)0.01011.75114186851212014.9867256637168421.0103.311141868512112014.986725663716810-0.01327433628318712014.986725663716810-0.01327433628318712011.72421.010-0.0132743362831871203.2810-0.0132743362831871200.0398230088495577103.28200.039823008849557421.01011.72200.03982300884955771015.0132743362832200.03982300884955771015.0132743362832203.28421.01015.01327433628322011.721015.01327433628322014.98672566371680折线5733301楼100实体8第一层100AcDb折线9012701430.01012.65446110510082015.98672566371681016.01327433628322015.98672566371681016.01327433628322012.623319236588742-0.8236847647248741016.0132743362832202.376680763411281016.013274336283220-0.9601769911504421012.623319236588720-0.96017699115044242-0.823684764724874102.3766807634112820-0.96017699115044310-1.0132743362831920-0.96017699115044210-1.01327433628319202.3766807634112842-0.82368476472487410-1.013274336283192012.623319236588710-1.013274336283192015.9867256637168102.407822631923392015.986725663716842-0.8236847647248740ENDSEC


相关问题

解决方案

最后一段(BLOCKS)是最长的,虽然我不知道那部分代表什么(如果你能解释一下就好了).

BLOCKS的目的> 部分总结在您参考的手册中:

<块引用>

BLOCKS 部分包含图形中每个块参考的条目.

将块视为一组作为一个元素组合在一起的实体.该块有:

  • 起源
  • 旋转
  • 规模

此类块在绘图本身中引用,块的每个实例称为一个INSERT.

因此,当您浏览 ENTITIES 部分并点击 INSERT 实体,然后你必须在 BLOCK 表中找到它的 handle 并处理元素相应地.


有些 DXF 代码对许多实体都是通用的,它们并不总是与特定实体类型的信息一起列出(例如 LWPOLYLINE).

看看这个这些数字的完整列表:

<块引用>
  • 5:实体句柄;最多 16 个十六进制数字的文本字符串(固定)

  • 330:软指针句柄;指向同一 DXF 文件或绘图中的其他对象的任意软指针.在 INSERTXREF 期间翻译操作

  • 100:子类数据标记(派生类名作为字符串).派生自的所有对象和实体类都需要另一个具体的类.子类数据标记隔离数据由继承链中的不同类为相同的目的.这是对每个 DXF 名称要求的补充从 ObjectARX 派生的不同的具体类(参见子类标记)

这个页面 也很有用.


<块引用>

为什么首先有 2 个 LWPOLYLINES,为什么不是只有一对 BLOCK-ENDBLK?

如果您通读了关于 BLOCKS 你会看到:

<块引用>

模型空间和图纸空间块定义

三个空定义总是出现在 BLOCKS 部分.他们是标题为 *Model_Space*Paper_Space*Paper_Space0.这些定义将模型空间纸空间的表示表示为块内部定义.第一个纸空间的内部名称布局是*Paper_Space,第二个是*Paper_Space0,第三个是*Paper_Space1,依此类推.

I would like to convert the drawings inside a .dxf file into g-code. There are tools doing that but I would like to code it myself. So, the very first part is to decode the .dxf format. Yet, the contents of the .dxf file does not look easy to decipher.

I downloaded a .dxf file here and opened it in a text editor.

I am also referring to this manual. It looks like what is inside a .dxf file is mostly style and configuration information and I tend to omit almost everything. So, 1. can you specify attributes that should not be omitted, if there are any?

As far as I know the figures are divided into multiple ENTITIES in a .dxf file. Therefore, I am only copy pasting the SECTION of ENTITIES. Note that there are 6 SECTIONS in the file and the last section (BLOCKS OBJECTS) is the longest one although I don't know what that part represents (Would be nice if you could explain).

In the code below, 10 and 20 should be representing X and Y positions and 42 should be representing the bulge. It is kind of possible to track the polyline. I consider extracting information from the file by using the TITLES as navigation points as well as the numbers like 10, 20 and 42. But there are two polylines below. So, 2. which polyline should I take into consideration and what is the purpose of the other?

  0
SECTION
  2
ENTITIES
  0
LWPOLYLINE
  5
72    # What
330   # are
1F    # these
100   # numbers?
AcDbEntity
  8
Layer 1
100
AcDbPolyline
 90
       12
 70
     1
 43    # Constant width (optional; default = 0)
0.0
 10
11.7511418685121
 20
14.9867256637168
 42
1.0
 10
3.31114186851211
 20
14.9867256637168
 10
-0.0132743362831871
 20
14.9867256637168
 10
-0.0132743362831871
 20
11.72
 42
1.0
 10
-0.0132743362831871
 20
3.28
 10
-0.0132743362831871
 20
0.0398230088495577
 10
3.28
 20
0.039823008849557
 42
1.0
 10
11.72
 20
0.0398230088495577
 10
15.0132743362832
 20
0.0398230088495577
 10
15.0132743362832
 20
3.28
 42
1.0
 10
15.0132743362832
 20
11.72
 10
15.0132743362832
 20
14.9867256637168
  0
LWPOLYLINE
  5
73
330
1F
100
AcDbEntity
  8
Layer 1
100
AcDbPolyline
 90
       12
 70
     1
 43
0.0
 10
12.6544611051008
 20
15.9867256637168
 10
16.0132743362832
 20
15.9867256637168
 10
16.0132743362832
 20
12.6233192365887
 42
-0.823684764724874
 10
16.0132743362832
 20
2.37668076341128
 10
16.0132743362832
 20
-0.960176991150442
 10
12.6233192365887
 20
-0.960176991150442
 42
-0.823684764724874
 10
2.37668076341128
 20
-0.960176991150443
 10
-1.01327433628319
 20
-0.960176991150442
 10
-1.01327433628319
 20
2.37668076341128
 42
-0.823684764724874
 10
-1.01327433628319
 20
12.6233192365887
 10
-1.01327433628319
 20
15.9867256637168
 10
2.40782263192339
 20
15.9867256637168
 42
-0.823684764724874
  0
ENDSEC


Related Questions

解决方案

The last section (BLOCKS) is the longest one although I don't know what that part represents (Would be nice if you could explain).

The purpose of the BLOCKS section is summaried in the manual you referred to:

The BLOCKS section contains an entry for each block reference in the drawing.

Think of a block as a group of entities that are grouped together as one element. The block has:

  • Origin
  • Rotation
  • Scale

Such blocks are referenced in the drawing itself and each instance of the block is called an INSERT.

So when you walk your ENTITIES section and you hit an INSERT entity, you then have to find its handle in the BLOCK table and process the elements accordingly.


There are some DXF codes that are common to many entities and they are not always listed with the information for a specific entity type (like LWPOLYLINE).

Look at this complete list for those numbers:

  • 5: Entity handle; text string of up to 16 hexadecimal digits (fixed)

  • 330: Soft-pointer handle; arbitrary soft pointers to other objects within same DXF file or drawing. Translated during INSERT and XREF operations

  • 100: Subclass data marker (with derived class name as a string). Required for all objects and entity classes that are derived from another concrete class. The subclass data marker segregates data defined by different classes in the inheritance chain for the same object. This is in addition to the requirement for DXF names for each distinct concrete class derived from ObjectARX (see Subclass Markers)

This page is also useful.


Why are there 2 LWPOLYLINES in the first place and why is it not only one BLOCK-ENDBLK pair?

If you read through the section about BLOCKS you'll see:

Model Space and Paper Space Block Definitions

Three empty definitions always appear in the BLOCKS section. They are titled *Model_Space, *Paper_Space and *Paper_Space0. These definitions manifest the representations of model space and paper space as block definitions internally. The internal name of the first paper space layout is *Paper_Space, the second is *Paper_Space0, the third is *Paper_Space1, and so on.

这篇关于如何解码 .dxf 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆