Resetting current color when a different layer is set as current

By Balaji Ramamoorthy

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);
}

Comments

One response to “Resetting current color when a different layer is set as current”

  1. what about changing objects colors when printing so cadd users can use their internal habitual colors but print using another companies ctb file. In other words, every object that is green (bylayer or byentity) upon print command changes to red (for instance) then changes back to green. This way a user can map their colors to an outside companies colors for plotting due to ctb file differences. Application could compare ctb files or just have a manual lookup table saved in a txt format. Maybe the option to convert colors permanently for digital dwg delivery.
    Time for me to learn arx maybe?

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading