You are currently reviewing an older revision of this page.
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
Byte
, intGreen
, intBlue
)
Dim
lngColor
lngColor = longColor
intRed = lngColor
Mod
&H100
lngColor = lngColor \ &H100
intGreen = lngColor
intBlue = lngColor
End
' extract colors from attached colortable
tbl2txt()
tbl
ColorTable
col()
r
, g
, b
bg
Set
tbl = ActiveDesignFile.ExtractColorTable
col = tbl.GetColors
Open ActiveDesignFile.FullName +
"-rgb values.csv"
For
Output
#1
Print #1,
"Number;Red;Green;Blue"
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
ExtractRGB(bg, r, g, b)
"BG;"
"; "
+ Str(b);
""
Close #1
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: