Setting the current color using the CECOLOR system variable helps create entities with a certain color irrespective of the color of the current layer. But when you set a different layer as current, you may want to the layer color to take effect.
So, How do I automatically change the current color to BYLAYER if the user changes the layer?
The current color can be set by AcDbDatabase::setCecolor(). You will be notified of system variable changes if you plant your own AcEditorReactor and override the member function sysVarChanged(). The system variable for the current layer is CLAYER.
class MyEditorReactor : public AcEditorReactor
{
public:
void sysVarChanged(const ACHAR* varName, Adesk::Boolean success);
};
MyEditorReactor *pReactor = NULL;
/*
* Set the current color
*/
void setCurColor(int index)
{
AcCmColor color;
color.setColorIndex(index);
acdbHostApplicationServices()->workingDatabase()->setCecolor(color);
}
/*
* System variable changed
*/
void MyEditorReactor::sysVarChanged(const ACHAR* varName, Adesk::Boolean
success)
{
if(success)
{
// change the current color to "ByLayer" if the layer
// was changed
if(!_tcscmp(L"CLAYER",varName))
setCurColor(256);
}
}
void initApp()
{
pReactor = new MyEditorReactor;
if(pReactor)
acedEditor->addReactor(pReactor);
}
void unloadApp()
{
if(pReactor)
acedEditor->removeReactor(pReactor);
}