For many projects, it may be necessary to evaluate color tables used throughout the drawings to extract RGB values to text files.
VBA provides the ability to directly access all of the colors. Every color value is stored as a Long so that the RGB values can be accessed individually.
Here is an example that reads all values of the current color table. The output is a CSV file, which is stored in the same directory as the open DGN.
' Convert Long to RGB Values Private Sub ExtractRGB(ByVal longColor As Long, intRed As Byte, intGreen As Byte, intBlue As Byte) Dim lngColor As Long lngColor = longColor intRed = lngColor Mod &H100 lngColor = lngColor \ &H100 intGreen = lngColor Mod &H100 lngColor = lngColor \ &H100 intBlue = lngColor Mod &H100 End Sub ' extract colors from attached colortable Sub tbl2txt() Dim tbl As ColorTable Dim col() As Long Dim r As Byte, g As Byte, b As Byte Dim bg As Long Set tbl = ActiveDesignFile.ExtractColorTable col = tbl.GetColors Open ActiveDesignFile.FullName + "-rgb values.csv" For Output As #1 Print #1, "Number;Red;Green;Blue" For i = LBound(col) To UBound(col) Call ExtractRGB(col(i), r, g, b) Print #1, Str(i) + ";" + Str(r) + ";" + Str(g) + ";" + Str(b) Next ' and Background color: bg = tbl.BackColor Call ExtractRGB(bg, r, g, b) Print #1, "BG;" + Str(r) + "; " + Str(g) + "; " + Str(b); "" Close #1 End Sub
To create the CSV file, the subroutine must be called tbl2txt.
An excerpt of the output in the .csv may then look something like this: