The Power Of CSV


 Product:MicroStation
 Version:All
 Environment:N\A
 Area:Annotations
 Subarea:N\A

Overview

In versions of MicroStation prior to MicroStation V8 there were mapping tables that allowed compatibility between MicroStation DGN files and AutoCAD DWG files. This was convenient when exporting DGN files to DWG files and vice-versa. Before MicroStation V8 there were only two file formats involved when mapping between AutoCAD and MicroStation. Now in the V8 era, we are encountered with a third file format, V8 DGN. The advantages to this "new" file format are extensive and have been well documented, as you can see from the SELECTservices MicroStation V8 Technical Support Documentation.

With MicroStation V8 there is a new and a more expedient way of mapping to other file formats, which includes pre-V8 DGN file formats. It is done with CSV (Comma Separated Value) files. This article will show examples of how to conveniently map to and from the aforementioned file formats.

In MicroStation v7, in order to import a DWG file, it was recommended to use the File>Import DWG/DXF Utility. This was the same when a DGN file was to be exported to a DWG format (File>Export>DWG/DXF).


Figure 1: The Save As DWG dialog box

The CSV file is created from an Excel spreadsheet. This spreadsheet is created when you save a file to another format or back to its original format. The dialog box that opens when you save to any file format contains an Options button. This button opens another dialog box that contains a certain number of tabs depending on the file format to which you are saving. In each Options dialog box there is a Remap tab, which contains five mapping options: Level, Font, Line Style, Color, and Weight. The three icons to the right of the CSV file field are, from left to right: Open a CSV file, Edit a CSV file, and Create a CSV file (See Figure 1).


Figure 2: The Excel XLS file that saves to the CSV file

Once you create a CSV file, Excel opens an XLS spreadsheet and you are prompted to Enable Macros. It is important that you choose to enable the macros in the file. One of the macros will save this file to a CSV file of the same name and in the same directory as the XLS file. In the spreadsheet there is an Instructions Worksheet that contains instructions for each of the Mapping Worksheets. This article will not go into great detail on these instructions, as this is already documented.

Also note the CellNames and System Worksheets (See Figure 2). The CellNames Worksheet does not have a corresponding toggle in the remapper GUI. The System Worksheet should not be modified as it is for the macros.

Common CSV Usages

The v7 file format has two major limitations compared to the V8 DGN format and DWG format. In v7, there is a limit of 63 levels per file, whereas in V8 and AutoCAD there is no limit to the number of levels in each file. Also, in V8 and DWG elements could take on ByLevel Attributes for Color, Line Styles, and Weights. For more on ByLevel Attributes refer to: http://selectservices.bentley.com/technotes/faqs/6202.htm

Many companies have level structures that incorporate certain standards. It would be cumbersome to have to upgrade v7 files to V8 and change all of the graphic elements to the desired levels and then to change the elements to take on the ByLevel Attributes. This can be easily done with CSV files when saving the v7 file to V8. To do this, I am going to introduce a few of the keywords that automate the mapping process. If the keyword "%unmapped" appears in the first column of a Color, Line Style, or Weight Worksheet, then every element that has a color, line style, or weight that does not otherwise appear in the first column is mapped to the destination specified in the "%unmapped" row. If there is more than one "%unmapped row" in the section with the same values for the qualifiers columns, the last one is used.

If the keyword "%bylevel" appears in the V8OutputColor or DwgOutputColor column, then every element that has the color, line style, or weight indicated is changed to be ByLevel. The v7 file format does not support ByLevel, so that keyword is invalid in the V7OutputColor column. Note that these definitions and more in depth column information are listed in each applicable Worksheet below the mapping data.


Figure 3a: V7 file open in V8 in V7 workmode

Below is an example of a v7 file that is opened in v7 Workmode in V8 (Figure 3). To open a v7 file in v7 Workmode, simply change the configuration variable MS_OPENV7 to a value of 3. As you can see there are elements on the levels on which they were created in v7, which creates a Level Name by adding "Level" before the v7 Level Number.

All of the attributes are "forced." The elements will remain forced and the level names will remain "Level #" when saved to V8 unless a CSV file is used to change them. It is usually desired to have a more descriptive level name. When saving to V8, create a spreadsheet with the following parameters:


Figure 3b: Level mapping from V7 to V8


Figure 3c: ByLevel mapping of colors

 
Figure 3d: The resultant V8 DGN

The Line Style and Weight Worksheets should contain the same values as Figure 3c.

As you see below, the resultant V8 file mapped the 4 levels to the desired names and created ByLevel attributes for Color, Line Style, and Weight. Also, the elements were changed to have ByLevel Attributes (Figure 3d).

This technique could be used to save to DWG format also.

Another common usage of CSV files is saving Weights to Color when saving to DWG. Before AutoCAD 2000, there was no such thing as Line Weight. In order to plot Weights, lines were drawn with certain colors and plotting files could be used to translate the colors to Line Weights at plot time. This example will show how to map DGN Line Weights to DWG Colors.


Figure 4a: Weight to color V8 DGN


Figure 4b: Weight to color weight worksheet

In the above sample there are multiple element types with different weights (Figure 4a). There are two different element types with a weight of two. In this example, I'm going to demonstrate how to map a type 16 (Arc) element to a color and not a type 3 (Line) element even though they are the same weight. This can be done with Optional Qualifiers. The Optional Qualifiers are hidden by default and can be viewed by checking the Show Optional Columns check box. The possible optional qualifiers are: Level, Color, Weight, Linestyle, Class, ElementType and Cell. I am also going to demonstrate how to map fonts. Please refer to Figure 4a again. Line Weight and the line weight numbers are font Engineering (a delivered MicroStation font) and the element descriptions below the elements are Arial (a true type font).

In Figure 4b, I choose to Hide the other qualifier columns to make the important columns visible.


Figure 4c: Weight to color font mapping

The brackets around the weight number tells the remapper (referring to the entire remapping process) to map all elements with the specified weight, as well as all elements with a weight of ByLevel and the ByLevel weight of their level set to the specified weight. The "ac" which follows the DWGOutputColor number tells the remapper to use AutoCAD's color table. The tilde (~) before the element type number tells the remapper to exclude that element type from the mapping process. CSV files can be read like a sentence from left to right. In the first row, map elements with a weight of 0 or a weight of ByLevel, with the ByLevel color of its Level set to 0-excluding type 17 (Text) elements-to AutoCAD's color 3. In the second row, map elements with a weight of 2 or a weight of ByLevel, with the ByLevel color of its Level set to 2 and an element type of 16 to AutoCAD's color 3.

Font Types


Figure 4d: Weight to color resultant DWG file

There are three font types in MicroStation V8. USTN are the standard MicroStation fonts delivered with all versions of MicroStation. TT fonts are true type fonts read by default from the Operating System. SHX are AutoCAD fonts. The mapping in Figure 4c will map a Line Weight of 0, 2, 4 and 6 to AutoCAD's simplex.shx. The element descriptions (arial.ttf) will be mapped to romans.shx.

Figure 4d shows the graphical results of the remapper. As you can see, the text, which is weight 0, was not mapped to Color 3 but the ellipse was. Also, of the two elements with a weight of 2, only the arc was mapped to Color 6. Though not very visible graphically, the text placed with the Engineering font mapped to simplex.shx and the text placed with arial.ttf mapped to romans.shx.

Mapping AutoCAD Line Types to V8 DGN Line Styles

In this final example, I will show how to map AutoCAD Line Types to V8 DGN Line Styles. MicroStation V8 stores DWG line styles internally, which allows a user to send the file to another user who in turn will be able to view the correct line styles without the need of an extra *.rsc file. Previous versions of MicroStation do not write line style information internally and rely on the *.rsc file for the definitions of the line styles. More on line styles and DWG files can be found at: http://selectservices.bentley.com/technotes/technotes/8240.htm.


Figure 5a: AutoCAD's Track Line Type

As stated in the above URL, AutoCAD supports a different and limited line style environment when compared to MicroStation V8. That said, it is often more desirable to map to MicroStation's more complex Line Styles.

Figure 5a shows AutoCAD's Track Line Type in MicroStation V8. Many MicroStation users prefer the DGN equivalent to Track-{ Rail Road }.

In Figure 5b, The Line Style to be mapped is AutoCAD's Tracks. It is mapped to MicroStation's


Figure 5b: Mapping line type to line style


Figure 5c: Resultant V8 file

{ Rail Road }. Tracks has a distance of .3 units between its ties and { Rail Road } has a distance of 4 units between its ties. I set a V8OutputScale to 0.075 to scale down the { Rail Road }, in turn making it equivalent in size to Tracks. Note that company standards may vary on line style scales.

As you can see, the line style is now MicroStation's { Rail Road }.

Additional Notes

· If you cannot utilize any of the macros such as "Show Optional Columns" and you are populating the Level and Font columns from a file, or if the five mapping Apply buttons will not become active to check, then you most likely have the Macro Security Level set to High in Excel. In Excel, go to Tools>Macro>Security and set the Security Level to at least Medium. This setting will allow you to enable macros upon opening an XLS file.

https://support.microsoft.com/en-us/office/change-macro-security-settings-in-excel-a97c09d2-c082-46b8-b19f-e8621e8fe373 

· A CSV file can be used with the Batch Converter Utility to batch convert files to any of the three file formats. The Batch Converter is in the Utilities pulldown in MicroStation. To attach a CSV file, go to the Edit pulldown and choose DWG Save Options, V8 Save Options, or V7 Save Options. For more on the Batch Converter:

See also

Batch Convert Utility TechNote

Other language sources

 Original Author:Erik Lofgren