Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
MicroStation
  • Product Communities
MicroStation
MicroStation Wiki Exporting the RGB Values of the Color Table to a Text File in VBA
    • Sign In
    • -MicroStation Wiki
      • +Learning Tips
      • -MicroStation
        • +3D Printing - MicroStation
        • +Animation - MicroStation
        • +Archive / Backup - MicroStation
        • +Base Geometry - MicroStation
        • +Batch Processing - MicroStation
        • +CONNECT Advisor - MicroStation
        • CONNECT Integration - MicroStation
        • +CONNECTION Client
        • +Cells - MicroStation
        • +Change Tracking - MicroStation
        • +Configuration - MicroStation
        • +Coordinate Systems - MicroStation
        • +Curves - MicroStation
        • +Custom Linestyles - MicroStation
        • +DGN - MicroStation
        • +DWG - MicroStation
        • +Database - MicroStation
        • +Detailing Symbols - MicroStation
        • +Dimensions - MicroStation
        • +Documentation & Help - MicroStation
        • +Drawing Aids - MicroStation
        • +Exception - MicroStation
        • +FAQ - MicroStation
        • +Feature Based Solids Modeling - MicroStation
        • +File Access - MicroStation
        • +GUI - MicroStation
        • +General - MicroStation
        • +Graphics Display - MicroStation
        • +Groups - MicroStation
        • +Hardware / Input Devices - MicroStation
        • +Import/Export - MicroStation
        • +Installation - MicroStation
        • +Interchange - MicroStation
        • +Interference - MicroStation
        • +Internationalization - MicroStation
        • +Levels - MicroStation
        • +Licensing - MicroStation
        • +Manipulation - MicroStation
        • +Markup / Redline - MicroStation
        • +Measure - MicroStation
        • +Mesh - MicroStation
        • +Models - MicroStation
        • +Multi-Lines - MicroStation
        • +OLE - MicroStation
        • +Other - MicroStation
        • +Parametrics - MicroStation
        • +Patterning - MicroStation
        • +Point Cloud - MicroStation
        • +Printing - MicroStation
        • -Programming - MicroStation
          • +General - Programming - MicroStation
          • +Macro Recorder - Programming - MicroStation
          • +MDL - Programming - MicroStation
          • -VBA - Programming - MicroStation
            • Automatic execution when opening or closing drawings
            • Automatic Subroutine Loading
            • Automatically generate plots with VBA
            • Avoiding Inaccuracies in VBA Methods - .FacetSolidAsShapes for SmartSolids
            • Bring All Text to a New Level with VBA
            • Browsing References for Specific Items
            • Calculating the range of Rotated Cells
            • Changing Colors of Levels in VBA
            • Changing display priority for references
            • Changing Element Colors from RGB to Indexed Color
            • Changing Layer Colors from RGB to an Indexed Color
            • Changing the Alignment of All Texts with VBA
            • Changing the display order of elements
            • Changing the presentation order of Layers
            • Changing the Transparency Settings of Levels with VBA
            • Cleaning Property Data with VBA
            • COM Server error
            • Create Engineering (HTML) Links in VBA
            • Creating Coordinates as Latitude and Longitude using VBA Lines
            • Creating VBA Levels - 'Level name is duplicate'
            • Deleting Lines of Length 0 Using VBA
            • Errors Attempting to Load VBA Projects
            • Errors while attempting to load VBA
            • Exporting the RGB Values of the Color Table to a Text File in VBA
            • Forms in an .mvba do not open some pc's
            • How to read the RGB values of the Attached Color Table
            • Keyin to load the VBA Project Manager in MicroStation Connect
            • Leaving a VBA Tools Dialog Box Open
            • Linking to VBA Elements with User Attributes
            • New Text Font Cannot be Assigned
            • Placing annotation cells with VBA
            • Print Organizer Control with VBA
            • Printing all Sheet Models to PDF Using VBA
            • Reading the Length of All Arcs
            • Removing All Object Data from Selected Cells in VBA
            • Replacing Points with Circles Using VBA
            • Replacing Text with VBA - Part 1: Introduction
            • Replacing Text with VBA - Part 2: Complex Structures
            • Running a VBA Routine by Keyin
            • +Searching and Evaluating Data in a drawing with VBA
            • Searching and Selecting Text Fields with VBA
            • Updating sequence control with VBA
            • Using a VBA Macro
            • Using the VBA object PropertyHandler to change the Element Information
            • VBA - Interface Error: 0x80040502
            • VBA Error in Execution: Project or Library Not Found
            • What are these "Default.mvba" files?
        • +Project Navigation - MicroStation
        • +Properties - MicroStation
        • +RSS Feeds - MicroStation
        • +Reference - MicroStation
        • +Security - MicroStation
        • +Selection - MicroStation
        • +Settings - MicroStation
        • +Sheet Composition - MicroStation
        • +Solids - MicroStation
        • +Standards - MicroStation
        • +Surfaces - MicroStation
        • +Tables - MicroStation
        • +Text - MicroStation
        • +UI Customization - MicroStation
        • +Units - MicroStation
        • +View - MicroStation
        • +Visualization - MicroStation
        • Welcome Page - MicroStation
        • +Accreditation - MicroStation
        • +i.Models - MicroStation
        • +ProjectWise Integration
        • +Raster - MicroStation
    • +Administration Wiki
    • +Annotations Wiki
    • +Bentley View Wiki
    • +MicroStation PowerDraft
    • +Printing and Plotting
    • +Programming Wiki
    • +Visualization Wiki
    • Window List Dialog for Missing Tool Dialog Boxes

    You are currently reviewing an older revision of this page.

    • History View current version

    Exporting the RGB Values of the Color Table to a Text File in VBA

       
      Applies To 
       
      Product(s): MicroStation
      Version(s): 08.11.09.578
      Environment:  Windows 7 32 bit,Windows 7 64 bit
      Area:  Programming
      Subarea:  VBA
      Original Author: Tristan Anderson, Bentley Technical Support Group
       

     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, ByVal LCType As Long, _
    ByVal lpLCData As String, ByVal cchData As Long) As Long
     
    Declare Function GetUserDefaultLCID% Lib "kernel32" ()
     
    Public Const LOCALE_SLIST = &HC
     
    ' This function reads what ListSeperator must be used for the CSV files
    Function GetListSeparator() As String
    Dim ListSeparator As String
    Dim iRetVal1 As Long
    Dim iRetVal2 As Long
    Dim lpLCDataVar As String
     
    Dim Position As Integer
    Dim Locale As Long
    GetListSeparator = ";"
    Locale = GetUserDefaultLCID()
     
    iRetVal1 = GetLocaleInfo(Locale, LOCALE_SLIST, lpLCDataVar, 0)
     
    ListSeparator = String$(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 If
     
    End Function
    ' Split a Long value in the RGB components
    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
     
    ' Extracts colors from the current colormap
    Sub tbl2txt()
    Dim tbl As ColorTable
    Dim col() As Long
    Dim r As Byte, g As Byte, b As Byte
    Dim bg As Long
    Dim Sep As String
        ' 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 As #1
        Print #1, "Number" + Sep + "Red" + Sep + "Green" + Sep + "Blue"
         
        ' Extract each color ofthe color chart and write it in the CSV file
        For 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
        Call ExtractRGB(bg, r, g, b)
        Print #1, "BG" + Sep + Str(r) + Sep + Str(g) + Sep + Str(b)
     
        Close #1
    End Sub

    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:

      Number           Red       Green          Blue
    0 255 255 255
    1 0 0 255
    2 0 255 0
    3 255 0 0
    4 255 255 0
    5 255 0 255
    6 255 127 0
    7 0 255 255
    8 64 64 64
    9 192 192 192
    10 254 0 96
    11 160 224 0
    12 0 254 160
    13 128 0 160
    14 176 176 176
    15 0 240 240
    16 240 240 240
    17 0 0 240
    18 0 240 0
    19 240 0 0
    20 240 240 0
    21 240 0 240
    22 240 122 0
    23 0 240 240
    24 240 240 240
    25 0 0 240
    26 0 240 0
    27 240 0 0
    28 240 240 0
    29 240 0 240
    30 240 122 0
    31 0 225 225
    32 225 225 225
    33 0 0 225
    34 0 225 0
    35 225 0 0
    36 225 225 0
    37 225 0 225
    38 225 117 0
    39 0 225 225
    40 225 225 225
    41 0 0 225
    42 0 225 0
    43 225 0 0
    44 225 225 0
    45 225 0 225
    46 225 117 0
    47 0 210 210
    48 210 210 210
    49 0 0 210
    50 0 210 0
    51 210 0 0
    52 210 210 0
    53 210 0 210
    54 210 112 0
    55 0 210 210
    56 210 210 210
    57 0 0 210
    58 0 210 0
    59 210 0 0
    60 210 210 0
    61 210 0 210
    62 210 112 0
    63 0 195 195
    64 195 195 195
    65 0 0 195
    66 0 195 0
    67 195 0 0
    68 195 195 0
    69 195 0 195
    70 195 107 0
    71 0 195 195
    72 195 195 195
    73 0 0 195
    74 0 195 0
    75 195 0 0
    76 195 195 0
    77 195 0 195
    78 195 107 0
    79 0 180 180
    80 180 180 180
    81 0 0 180
    82 0 180 0
    83 180 0 0
    84 180 180 0
    85 180 0 180
    86 180 102 0
    87 0 180 180
    88 180 180 180
    89 0 0 180
    90 0 180 0
    91 180 0 0
    92 180 180 0
    93 180 0 180
    94 180 102 0
    95 0 165 165
    96 165 165 165
    97 0 0 165
    98 0 165 0
    99 165 0 0
    100 165 165 0
    101 165 0 165
    102 165 97 0
    103 0 165 165
    104 165 165 165
    105 0 0 165
    106 0 165 0
    107 165 0 0
    108 165 165 0
    109 165 0 165
    110 165 97 0
    111 0 150 150
    112 150 150 150
    113 0 0 150
    114 0 150 0
    115 150 0 0
    116 150 150 0
    117 150 0 150
    118 150 92 0
    119 0 150 150
    120 150 150 150
    121 0 0 150
    122 0 150 0
    123 150 0 0
    124 150 150 0
    125 150 0 150
    126 150 92 0
    127 0 135 135
    128 135 135 135
    129 0 0 135
    130 0 135 0
    131 135 0 0
    132 135 135 0
    133 135 0 135
    134 135 87 0
    135 0 135 135
    136 135 135 135
    137 0 0 135
    138 0 135 0
    139 135 0 0
    140 135 135 0
    141 135 0 135
    142 135 87 0
    143 0 120 120
    144 120 120 120
    145 0 0 120
    146 0 120 0
    147 120 0 0
    148 120 120 0
    149 120 0 120
    150 120 82 0
    151 0 120 120
    152 120 120 120
    153 0 0 120
    154 0 120 0
    155 120 0 0
    156 120 120 0
    157 120 0 120
    158 120 82 0
    159 0 105 105
    160 105 105 105
    161 0 0 105
    162 0 105 0
    163 105 0 0
    164 105 105 0
    165 105 0 105
    166 105 77 0
    167 0 105 105
    168 105 105 105
    169 0 0 105
    170 0 105 0
    171 105 0 0
    172 105 105 0
    173 105 0 105
    174 105 77 0
    175 0 90 90
    176 90 90 90
    177 0 0 90
    178 0 90 0
    179 90 0 0
    180 90 90 0
    181 90 0 90
    182 90 72 0
    183 0 90 90
    184 90 90 90
    185 0 0 90
    186 0 90 0
    187 90 0 0
    188 90 90 0
    189 90 0 90
    190 90 72 0
    191 0 75 75
    192 75 75 75
    193 0 0 75
    194 0 75 0
    195 75 0 0
    196 75 75 0
    197 75 0 75
    198 75 67 0
    199 0 75 75
    200 75 75 75
    201 0 0 75
    202 0 75 0
    203 75 0 0
    204 75 75 0
    205 75 0 75
    206 75 67 0
    207 0 60 60
    208 60 60 60
    209 0 0 60
    210 0 60 0
    211 60 0 0
    212 60 60 0
    213 60 0 60
    214 60 62 0
    215 0 60 60
    216 60 60 60
    217 0 0 60
    218 0 60 0
    219 60 0 0
    220 60 60 0
    221 60 0 60
    222 60 62 0
    223 0 45 45
    224 45 45 45
    225 0 0 45
    226 0 45 0
    227 45 0 0
    228 45 45 0
    229 45 0 45
    230 45 57 0
    231 0 45 45
    232 45 45 45
    233 0 0 45
    234 0 45 0
    235 45 0 0
    236 45 45 0
    237 45 0 45
    238 45 57 0
    239 0 30 30
    240 30 30 30
    241 0 0 30
    242 0 30 0
    243 30 0 0
    244 30 30 0
    245 30 0 30
    246 30 52 0
    247 0 30 30
    248 30 30 30
    249 0 0 30
    250 0 30 0
    251 30 0 0
    252 30 30 0
    253 30 0 30
    254 192 192 192
    BG 0 0 0

     

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies