编写 DXF 文件 (DXF)
与编写读取 DXF 文件的程序相比,编写创建 DXF 文件的程序更困难,因为必须保持图形的一致性,这样基于 AutoCAD 的程序才能找到可接受的文件。基于 AutoCAD 的程序使您可以省略 DXF 文件中的很多内容,而仍然能够获得可用的图形。
以下 Visual Basic 6 子例程创建了表示多边形的 DXF 文件。 ' WriteDXFPolygon creates a minimal DXF file that only contains
' the ENTITIES section. This subroutine requires five parameters,
' the DXF file name, the number of sides for the polygon, the X
' and Y coordinates for the bottom end of the right-most side
' (it starts in a vertical direction), and the length for each
' side. Note that because this only requests 2D points, it does
' not include the Z coordinates (codes 30 and 31). The lines are
' placed on the layer "Polygon."
'
Sub WriteDXFPolygon( _
dxfFile As String, iSides As Integer, _
dblX As Double, dblY As Double, dblLen As Double)
Dim i As Integer
Dim dblA1, dblA, dblPI, dblNX, dblNY As Double
Open dxfFile For Output As #1
Print #1, 0
Print #1, "SECTION"
Print #1, 2
Print #1, "ENTITIES"
dblPI = Atn(1) * 4
dblA1 = (2 * dblPI) / iSides
dblA = dblPI / 2
For i = 1 To iSides
Print #1, 0
Print #1, "LINE"
Print #1, 8
Print #1, "Polygon"
Print #1, 10
Print #1, dblX
Print #1, 20
Print #1, dblY
dblNX = dblLen * Cos(dblA) + dblX
dblNY = dblLen * Sin(dblA) + dblY
Print #1, 11
Print #1, dblNX
Print #1, 21
Print #1, dblNY
dblX = dblNX
dblY = dblNY
dblA = dblA + dblA1
Next i
Print #1, 0
Print #1, "ENDSEC"
Print #1, 0
Print #1, "EOF"
Close #1
End Sub
只要在需要数据的行上写入了格式正确的项目,DXFIN 就会接受该项目。(当然,字符串项目不应该包含前导空格,除非这些空格是字符串的一部分。)此 BASIC 程序利用了输入格式的灵活性,它生成的文件与基于 AutoCAD 的程序生成的文件并不完全相同。 如果使用 DXFIN 加载 DXF 文件时出现错误,则基于 AutoCAD 的程序将通过一条信息报告该错误,指明错误的性质以及检测到错误之前在 DXF 文件中处理的最后一行数据。错误可能并不出现在这一行,尤其是当出现省略所需组这样的错误时更是如此。 相关参考父主题: |
|Archiver|CAD开发者社区
( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-11-1 08:26
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.