[v8i MDL] mdlElement_getSymbology function dilemma

Hi,

mdlElement_getSymbology() function was returning color codes between 0-255 until my application gave an exception yesterday. :) If you set element's color as "dim grey" it returns a color code around 41000 or something similiar. I checked the documentation again but there is no option to understand the type of color returned.

The question is;

How can I understand that mdlElement_getSymbology() function returns a color code from color table (0-255) or a custom color code?

void mdlElement_getSymbology  
( 
UInt32* color , 
UInt32* weight , 
Int32* style , 
MSElement const* el  
); 

Description
Extracts the color, weight and style from the element pointed to by element. This function puts the extracted values in the variables pointed to by color, weight and style. If parameters other than element are NULL, MicroStation does not fill in the value. If the color, weight and style of the element are by the level (BYLEVEL) or by cell (BYCELL) then the values returned will be equal to the constants: COLOR_BYLEVEL COLOR_BYCELL STYLE_BYLEVEL STYLE_BYCELL WEIGHT_BYLEVEL WEIGHT_BYCELL

Regards,

Sedat Alis

AEC Technology, Inc.

  • mdlElement_getSymbology() function was returning color codes between 0-255

    MDL help tells us: Extracts the color, weight and style from the element pointed to by element. This function puts the extracted values in the variables pointed to by color, weight and style. If parameters other than element are NULL, MicroStation does not fill in the value. If the color, weight and style of the element are by the level (BYLEVEL) or by cell (BYCELL) then the values returned will be equal to the constants: COLOR_BYLEVEL COLOR_BYCELL STYLE_BYLEVEL STYLE_BYCELL WEIGHT_BYLEVEL WEIGHT_BYCELL.

    Check the colour value against COLOR_BYLEVEL and COLOR_BYCELL.

    You might want to use mdlElement_getEffectiveSymbology().  From MDL help: Extracts the effective color, weight, style and fill color from the element. If the element's color, weight or style is BYLEVEL or BYCELL, then the function will resolve the BYLEVEL/BYCELL symbology to get symbology of the element as displayed on screen. This function also takes in a "viewIndexIn" parameter. This is used to resolve the element's symbology when "level symbology" is turned on for the view represented by "viewIndex".

    Lastly, MicroStation XM and later have been able to render a 24-bit colour palette in addition to the legacy 255 colour table.  I believe that a 24-bit index (not a 24-bit RGB value) into an extended colour map and a legacy 8-bit palette index are packed into a DGN 32-bit colour.  If you're only interested in the 255-colour palette, then you may need to convert 24-bit to 8-bit.  Use one of the convertor functions such as mdlColor_elementColorFromRGB().

     
    Regards, Jon Summers
    LA Solutions

  • Thank you so much Jon.
    None of these functions gives me the option to decode the color code. Slight smile

    Kind regards,

    Sedat Alis
    AEC Technology Inc.

  • I believe that a 24-bit RGB colour and an 8-bit palette index are packed into a DGN 32-bit colour. 

    The low 2 bytes are the 0-255 index of the closest match in the color table (if the extended color is red, but the color table is grayscale the closest match isn't going to be very close). Masking the color value to just be the low 2 bytes is what is used for display if a file with extended colors is opened in an older version (see mdlColor_v8ColorFromRawColor).

    The high bytes represent an index into an extended color map, it's not a rgb value, this index references a color entry that optionally can store a color book name and color entry name in addition to the rgb value. There are also the special values COLOR_BYLEVEL and COLOR_BYCELL as mentioned that should be explicitly tested.

    In V8i you can use mdlColor_rgbColorFromRawColor to get the rgb value associated with an extended color value.

    In MicroStation Connect DgnColorMap provides methods for creating and extracting information for extended colors. See DgnColorMap::ExtractElementColorInfo.

    //! Get the color information from the supplied element color id.
    //! @param[out] colorDef IntColorDef for the supplied element color, can be used to get TBGR or RGB color values.
    //! @param[out] colorIndex The 0 to INDEX_Background index into the file's DgnColorMap. For rgb and book colors this is the closest match from when they were created.
    //! @param[out] isTrueColor True if supplied element color is a rgb or book color, false for color index.
    //! @param[out] bookName Color book name for the supplied element color (empty string for rgb and indexed colors).
    //! @param[out] colorName Color name from color book for the supplied element color (empty string for rgb and indexed colors).
    //! @param[in] elementColor The element color to extract the information for.
    //! @param[in] dgnFile The file for the supplied element color.
    //! @return SUCCESS if element color is a valid rgb, book, or DgnColorMap index.
    //! COLOR_BYLEVEL or COLOR_BYCELL will return ERROR.
    static DGNPLATFORM_EXPORT StatusInt ExtractElementColorInfo (IntColorDef* colorDef, UInt32* colorIndex, bool* isTrueColor, WStringP bookName, WStringP colorName, UInt32 elementColor, DgnFileR dgnFile);

    HTH

    -B

    NOTE; mdlColor_elementColorFromRGB returns the index of the closest match to the supplied rgb in the 0-255 color table, it's what is actually called to populate the low 2 bytes of the extended color value.



  • Brien,

    Thank you so much for the detailed information.

    When I select some elements, Element Selection Tool shows which colors are selected. Dimension element has a custom color called "blue". The element on the left side has RGB color. Other elements has index colors from active color table which are 139 and 234. MicroStation knows selected element's color as an index color, a custom color or a RGB color. But I don't know how to differenciate these colors in MDL. :) There must be a way to reach the element's exact color information within v8i MDL.

    Kind regards,

    Sedat Alis
    AEC Technology Inc.

  • None of these functions gives me the option to decode the color code
    There must be a way to reach the element's exact color information

    What do you mean by 'color code'?  What 'exact color information' do you want to obtain?

    Do you want...

    • A true colour RGB (24-bit) colour?
    • A Color Table (8-bit) index?
    • The RGB value indicated by a Color Table index?
    • Something else?

     
    Regards, Jon Summers
    LA Solutions

  • What do you mean by 'color code'?  What 'exact color information' do you want to obtain?

    Do you want...

    • A true colour RGB (24-bit) colour?
    • A Color Table (8-bit) index?
    • The RGB value indicated by a Color Table index?
    • Something else?

    On the active color selection palette, you have 4 options.

    1. Color index 0-255

    2. Standard colors

    3. RGB color

    4. ByLevel (or ByCell)

    I want to find which color is selected by user for a particular element. I can see the color selected by the user on Choose Element tool (as shown below) but I can't reach that information inside MDL. I don't want to convert any color type. I want to get selected color type and its value.

    Is it clear now?

    Kind regards,

    Sedat Alis
    AEC Technology Inc.

  • As I know, if the color value is 0~6, it can also be displayed in a color word. for example, 0=white, 1=blue, 2=green, 3=red, 4=yellow, 5=violet, 6=orange.

    if the color value is 0~255, then it is an index color. When it is greater than 7, it can only by displayed in a number rather than a word.

    if the color value is greater than 255, then it is a true color and you can use mdlColor_rgbColorFromRawColor  to get its corresponding RGB values.

    if the color value is -1, then it is a color by level.



  • On the active color selection palette, you have 4 options.

    1. Color index 0-255

    2. Standard colors

    3. RGB color

    4. ByLevel (or ByCell)

    There are only 3 cases to test, special color value, extended color, and 0-255 color table index.

    Test the color value as follows:

    - Check if COLOR_ByLevel or COLOR_ByCell
    - Check if mdlColor_rgbColorFromRawColor, returns SUCCESS, if so it's an extended color map entry and you have the RGB
    - It's a 0-255 index into the file's color table

    Getting the optional color book name and color name (ex. blue) for an extended color doesn't appear possible using the published api in V8i. As mentioned previously, an extended color can optionally reference an entry from a color book. This information is available in Connect using the DgnColorMap api previously mentioned (in lieu of mdlColor_rgbColorFromRawColor).

    As I know, if the color value is 0~6, it can also be displayed in a color word. for example, 0=white, 1=blue, 2=green, 3=red, 4=yellow, 5=violet, 6=orange.

    In this case the names are color book entry names (likely from the "Standard" color book, we do not try to show names for the 0-255 color table entries, the RGB values associated with the 0-255 color index is dependent on the color table, i.e. 2 is only green if you are using the default DGN color table.

    HTH

    -B