Transcription of Text File Writer - LA Solutions
1 LA SolutionsImplementing a Text File Writer with MVBAC opyright 2005 LA Solutions and again a question pops up on the Bentley discussion groups about text files,and how to write data from microstation to a formatted file. TheTextFileWriter exampleshows you that you have a microstation design file that contains some tag data, and youwant to export the data for analysis in your favourite spreadsheet. You decide to export datafrom tagged elements to a comma-separated-format (CSV) file, a format that many officeapplications can read. I ve included a design filewith a defined Tag Set in the ZIP archivewhere you found this PDF Tag Set is namedLA_Solutions and contains three Tag definitions ..Tag NameData TypeDefault ValueNameCharacterBox method used towrite tag data implements these steps.
2 A name for the text file, using a Windows Common aFileSystemObject from the Windows Scripting library to open the aTextStream object to write each line to the the design file, usingScanCriteria set to find tagged each element s Tag Data and format into a line of the line to theTextStreamOnce the design file is completely scanned, we have list of exported data in CSV format. I veprovided a sample output in the ZIP archive. It looks like this ..4, ,"Box 6"1,30,"Box 7"1, ,"Box 8"3, ,"Box 9"2, ,"Box 10"1, ,"Box 1"1, ,"Box 2"1,25,"Box 3"1, ,"Box 4"2, ,"Box 5"You can open a CSV file with a text editor, such as Windows Notepad or a more sophisticatedproduct likeTextPad. More usefully, you can open it with a spreadsheet or import it into ZIP archive includes MVBA project Unpack this archiveinto one of the folders in yourMS_VBASEARCHDIRECTORIES configuration variable;normally, this includes the folderC:\ProgramFiles\Bentley\Workspace\ Standards\vba.
3 Next, start MicroStationand load this project. You ll need to add a reference to the Windows Scripting library, whichwe use to create aTextStream object for writing to a text file. In the VBA editor, choosetheTools|References menu. Scroll down the list to find the library, and check the box on theleft. Click theOK button to complete adding the the supplied , or any other file that contains tagged elements. RunTextFileWriter from the IDE, starting at procedureMain, or from microstation using thekeyinvba run [TextFileWriter] The code asks for asave file name, then scans the design file for tagged elements. For each tagged element itfinds, it formats a line that is written to the named output SolutionsImplementing a Text File Writer with MVBAC opyright 2005 LA Solutions VBA code doesn t just scan the active model: it also scans any referenced models.
4 Thisillustrates how to iterate the reference collection, and to extract tag definitions from modelreferences other than the active microstation VBA is ready for action and browsing, soyou can see the code described above. You can download it from thePublications page ofour web site. It s in a ZIP archive with a sample design file, unimaginatively