Q How can I create a CSV file of the RBG colours in a MicroStation color table?

MicroStation Help: Color Table

Questions similar to this, posed by MicroStation users and VBA developers, appear on the color table typically the MicroStation Forum or Programming Forum.

A This VBA project implements a utility for analysing a MicroStation color table and creating a CSV file of its contents.

Introduction

MicroStation users sometimes want something different from the set of tools provided in the product. The Color Table is familiar to all MicroStation users. It provides 255 colours made up of red-green-blue (RGB) triplets.

VBA CSV Writer

It's straightforward to create a CSV file and write colour data. I wrote VBA class clsColor to store RGB data and handle conversion from the text supplied by the CSV file and conversion to a Long value used in a MicroStation Color Table.

The CSV writer references the Scripting.FileSystem object, which supplies the useful TextStream class.

Export Color Table Dialog

Export Color Table Dialog

The app's dialog (VBA UserForm) prompts user to specify a color CSV file, using the Save As button. When user clicks the Export Colour Table button, the macro reads the colour table and attempt to convert its contents into a CSV file.

Microsoft Scripting Runtime

Scripting.Dictionary Reference

The scripting DLL is almost certainly already installed on your Windows computer. The VBA project discussed here references that DLL. It uses the Scripting.FileSystemObject in the CSV text reader. It uses the Scripting.Dictionary object when it builds a collection of RGB values. To use those objects, which are not delivered with VBA, you must add a reference to Microsoft Scripting Runtime in your VBA project. In the VBA IDE, choose menu Tools|References to open the VBA References dialog.

Download the Color Table Exporter VBA Project

Download Color Table Exporter.ZIP

The above code is available in this MicroStation VBA project. Unpack the ZIP archive and copy ColorTableCsvExporter.mvba to a location where MicroStation can find it. A good place to copy it would be \Workspace\Standards\macros. To create a new color CSV file, type the following into MicroStation's key-in dialog …

vba run [ColorTableCsvExporter]modMain.Main

The exporter creates a CSV file in the same folder as your DGN file. The file name is the same as the DGN file with a csv extension.

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.