[MSCE U16 C++] change Element color to Colorbook Color.

Hi Guys,

I neet to set the color of an Element to a the color CLASSIC 840-HR:6006.

At the moment I'm only capable of passing a Color Index to the element using the Code:

	DgnFileP activeDgnFile = ISessionMgr::GetActiveDgnFile();



	ColorBookPtr colorBook;
	RgbColorDef colorDef;

	DgnHostR  dgnHost = ISessionMgr::GetManager().GetMicroStationDgnHost();
	
	ColorBook::LoadFromDgn(colorBook, L"RAL Classic 840-HR", activeDgnFile, true, dgnHost);
	colorBook->FindColorByName(&colorDef, L"5007");
	
	int colorID = mdlColor_convertRGBtoIndex(0, &colorDef);
	
	ElementPropertiesSetterPtr propsSetter = ElementPropertiesSetter::Create();
	propsSetter->SetColor(colorID);
	auto succ = propsSetter->Apply(eeh);
	auto stat = eeh.ReplaceInModel(eeh.GetElementRef());

Is it possible to set the Colorbook Color Directly without using "mdlColor_convertRGBtoIndex".

Similar to  the KeyIn "ACTIVE COLOR RAL CLASSIC 840-HR:6006"

Greetings 

Manu

Parents
  • s it possible to set the Colorbook Color Directly without using "mdlColor_convertRGBtoIndex".

    What can be stored in Disp_hdr.symb.color is a 0-255 index into the file's color table, an extended index representing a book or rgb color, and special values like COLOR_BYLEVEL and COLOR_BYCELL.

    So, before you can use a color representing a color book entry, an extended index for that color needs to be added to the file's extended color table.

    You do not however want to use mdlColor_convertRGBtoIndex for this purpose as that function returns the closest match for the supplied rgb in the 0-255 color table only.

    Have a look at the DgnColorMap class.

    After using ColorBook::FindColorByName to get the rgb value, use DgnColorMap::CreateElementColor to return the color index value you can apply to your element (this will create a new extended index for the color if it doesn't already exist).

    //! Get a element color id that can be stored on an element from the supplied IntColorDef.
    //! @param[in] colorDef Color table name.
    //! @param[in] bookName Color book name for the supplied IntColorDef (can be NULL).
    //! @param[in] colorName Color name in color book of the supplied IntColorDef (can be NULL).
    //! @param[in] dgnFile The file for the new element color.
    //! @note A valid element color id is one of the following:
    //! \li COLOR_BYLEVEL
    //! \li COLOR_BYCELL
    //! \li An index into a files DgnColorMap (value from 0 to INDEX_Background).
    //! \li A color book or rgb color id as returned by CreateElementColor.
    //! @return element color or INVALID_COLOR.
    static DGNPLATFORM_EXPORT UInt32 CreateElementColor (IntColorDef const& colorDef, WCharCP bookName, WCharCP colorName, DgnFileR dgnFile);

    HTH

    -B



Reply
  • s it possible to set the Colorbook Color Directly without using "mdlColor_convertRGBtoIndex".

    What can be stored in Disp_hdr.symb.color is a 0-255 index into the file's color table, an extended index representing a book or rgb color, and special values like COLOR_BYLEVEL and COLOR_BYCELL.

    So, before you can use a color representing a color book entry, an extended index for that color needs to be added to the file's extended color table.

    You do not however want to use mdlColor_convertRGBtoIndex for this purpose as that function returns the closest match for the supplied rgb in the 0-255 color table only.

    Have a look at the DgnColorMap class.

    After using ColorBook::FindColorByName to get the rgb value, use DgnColorMap::CreateElementColor to return the color index value you can apply to your element (this will create a new extended index for the color if it doesn't already exist).

    //! Get a element color id that can be stored on an element from the supplied IntColorDef.
    //! @param[in] colorDef Color table name.
    //! @param[in] bookName Color book name for the supplied IntColorDef (can be NULL).
    //! @param[in] colorName Color name in color book of the supplied IntColorDef (can be NULL).
    //! @param[in] dgnFile The file for the new element color.
    //! @note A valid element color id is one of the following:
    //! \li COLOR_BYLEVEL
    //! \li COLOR_BYCELL
    //! \li An index into a files DgnColorMap (value from 0 to INDEX_Background).
    //! \li A color book or rgb color id as returned by CreateElementColor.
    //! @return element color or INVALID_COLOR.
    static DGNPLATFORM_EXPORT UInt32 CreateElementColor (IntColorDef const& colorDef, WCharCP bookName, WCharCP colorName, DgnFileR dgnFile);

    HTH

    -B



Children
No Data