28.11.2014 Views

AutoCAD® 2002 - Autodesk

AutoCAD® 2002 - Autodesk

AutoCAD® 2002 - Autodesk

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

The following Visual Basic subroutine constructs a DXF file representing a<br />

polygon.<br />

' WriteDXFPolygon creates a minimal DXF file that only contains<br />

' the ENTITIES section. This subroutine requires five parameters,<br />

' the DXF file name, the number of sides for the polygon, the X<br />

' and Y coordinates for the bottom end of the right-most side<br />

' (it starts in a vertical direction), and the length for each<br />

' side. Note that because this only requests 2D points, it does<br />

' not include the Z coordinates (codes 30 and 31). The lines are<br />

' placed on the layer "Polygon."<br />

'<br />

Sub WriteDXFPolygon( _<br />

dxfFile As String, iSides As Integer, _<br />

dblX As Double, dblY As Double, dblLen As Double)<br />

Dim i As Integer<br />

Dim dblA1, dblA, dblPI, dblNX, dblNY As Double<br />

Open dxfFile For Output As #1<br />

Print #1, 0<br />

Print #1, "SECTION"<br />

Print #1, 2<br />

Print #1, "ENTITIES"<br />

dblPI = Atn(1) * 4<br />

dblA1 = (2 * dblPI) / iSides<br />

dblA = dblPI / 2<br />

For i = 1 To iSides<br />

Print #1, 0<br />

Print #1, "LINE"<br />

Print #1, 8<br />

Print #1, "Polygon"<br />

Print #1, 10<br />

Print #1, dblX<br />

Print #1, 20<br />

Print #1, dblY<br />

dblNX = dblLen * Cos(dblA) + dblX<br />

dblNY = dblLen * Sin(dblA) + dblY<br />

Print #1, 11<br />

Print #1, dblNX<br />

Print #1, 21<br />

Print #1, dblNY<br />

dblX = dblNX<br />

dblY = dblNY<br />

dblA = dblA + dblA1<br />

Next i<br />

Print #1, 0<br />

Print #1, "ENDSEC"<br />

Print #1, 0<br />

Print #1, "EOF"<br />

Close #1<br />

End Sub<br />

As long as a properly formatted item appears on the line on which the data<br />

is expected, DXFIN accepts it. (Of course, string items should not have leading<br />

spaces unless these are intended to be part of the string.) This BASIC program<br />

ASCII DXF Files | 157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!