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.

' ReadDXF extracts specified code/value pairs from a DXF file.<br />

' This function requires four string parameters, a valid DXF<br />

' file name, a DXF section name, the name of an object in that<br />

' section, and a comma delimited list of codes.<br />

'<br />

Function ReadDXF( _<br />

ByVal dxfFile As String, ByVal strSection As String, _<br />

ByVal strObject As String, ByVal strCodeList As String)<br />

Dim tmpCode, lastObj As String<br />

Open dxfFile For Input As #1<br />

' Get the first code/value pair<br />

codes = ReadCodes<br />

' Loop through the whole file until the "EOF" line<br />

While codes(1) "EOF"<br />

' If the group code is '0' and the value is 'SECTION' ..<br />

If codes(0) = "0" And codes(1) = "SECTION" Then<br />

' This must be a new section, so get the next<br />

' code/value pair.<br />

codes = ReadCodes()<br />

' If this section is the right one ..<br />

If codes(1) = strSection Then<br />

' Get the next code/value pair and ..<br />

codes = ReadCodes<br />

' Loop through this section until the 'ENDSEC'<br />

While codes(1) "ENDSEC"<br />

' While in a section, all '0' codes indicate<br />

' an object. If you find a '0' store the<br />

' object name for future use.<br />

If codes(0) = "0" Then lastObj = codes(1)<br />

' If this object is one you're interested in<br />

If lastObj = strObject Then<br />

' Surround the code with commas<br />

tmpCode = "," & codes(0) & ","<br />

' If this code is in the list of codes ..<br />

If InStr(strCodeList, tmpCode) Then<br />

' Append the return value.<br />

ReadDXF = ReadDXF & _<br />

codes(0) & "=" & codes(1) & vbCrLf<br />

End If<br />

End If<br />

' Read another code/value pair<br />

codes = ReadCodes<br />

Wend<br />

End If<br />

Else<br />

codes = ReadCodes<br />

End If<br />

Wend<br />

Close #1<br />

End Function<br />

' ReadCodes reads two lines from an open file and returns a two item<br />

' array, a group code and its value. As long as a DXF file is read<br />

' two lines at a time, all should be fine. However, to make your<br />

' code more reliable, you should add some additional error and<br />

' sanity checking.<br />

ASCII DXF Files | 155

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

Saved successfully!

Ooh no, something went wrong!