You are currently reviewing an older revision of this page.
Background Information
The colors used in Signatures can be displayed or changed on the color chart. Often, however, there is a desire to write an overview of all RGB values to get the colors.
Steps
You can use VBA to export the color values into a text file. Thus, the output file can be easily evaluated. I will show in the following example, how to export into a CSV file.
Here is the example of a subroutine "tbl2txt":
Declare
Function
GetLocaleInfo
Lib
"kernel32"
Alias
_
"GetLocaleInfoA"
(
ByVal
Locale
As
Long
,
LCType
, _
lpLCData
String
cchData
)
GetUserDefaultLCID%
()
Public
Const
LOCALE_SLIST = &HC
' This function reads what ListSeperator must be used for the CSV files
GetListSeparator()
Dim
ListSeparator
iRetVal1
iRetVal2
lpLCDataVar
Position
Integer
GetListSeparator =
";"
Locale = GetUserDefaultLCID()
iRetVal1 = GetLocaleInfo(Locale, LOCALE_SLIST, lpLCDataVar, 0)
ListSeparator =
$(iRetVal1, 0)
iRetVal2 = GetLocaleInfo(Locale, LOCALE_SLIST, ListSeparator, iRetVal1)
Position = InStr(ListSeparator, Chr$(0))
If
Position > 0
Then
ListSeparator = Left$(ListSeparator, Position - 1)
GetListSeparator = ListSeparator
End
' Split a Long value in the RGB components
Private
Sub
ExtractRGB(
longColor
, intRed
Byte
, intGreen
, intBlue
lngColor
lngColor = longColor
intRed = lngColor
Mod
&H100
lngColor = lngColor \ &H100
intGreen = lngColor
intBlue = lngColor
' Extracts colors from the current colormap
tbl2txt()
tbl
ColorTable
col()
r
, g
, b
bg
Sep
' Read the seperator in .csv files
Sep = GetListSeparator
' Read color table of active drawing file
Set
tbl = ActiveDesignFile.ExtractColorTable
col = tbl.GetColors
' Open the CSV file for output
Open ActiveDesignFile.FullName +
"-rgb values.csv"
For
Output
#1
Print #1,
"Number"
+ Sep +
"Red"
"Green"
"Blue"
' Extract each color ofthe color chart and write it in the CSV file
i = LBound(col)
To
UBound(col)
Call
ExtractRGB(col(i), r, g, b)
Print #1, Str(i) + Sep + Str(r) + Sep + Str(g) + Sep + Str(b)
Next
' List the Background Color:
bg = tbl.BackColor
ExtractRGB(bg, r, g, b)
"BG"
+ Sep + Str(r) + Sep + Str(g) + Sep + Str(b)
Close #1
The addition delaraion of functions or subroutines are used to further the reading of the separator for CSV files or for splitting a long value in the RGB components in bytes.
For the standard color table in MicroStation:
outputs the following with the VBA routine: