Code Red => ARX Programming => Topic started by: mjguzik on January 16, 2007, 09:02:04 PM

Title: Creating Layer Filters
Post by: mjguzik on January 16, 2007, 09:02:04 PM
After gaining so much from so many at this site, I believe it is appropriate to make a contribution after some trial and error.  Any suggestions for improvement would be greatly welcomed as I am still learning C++ (4 months) after years in lisp and VBA.  Of particular concern is releasing the pointers to the objects, but believe it is safe after looking at the AcLyLayerFilter and Manager class file. Thoughts?

Again, fantastic site!

Code: [Select]
// Function name : mg_CreateLayerFilter
// Description : Create or update a Layer filter
// Return type : void
// Argument : const ACHAR filtername
// Argument : const ACHAR filterexp
// Example : mg_CreateLayerFilter(_T("NOXREF"), _T("NAME==\"~*|*\""));
void mg_CreateLayerFilter(LPCTSTR filtername, LPCTSTR filterexp) {

    bool flag = false;

    AcLyLayerFilter* pRoot;
    AcLyLayerFilter* pCurrent;
    AcLyLayerFilter* pFilter;
    AcLyLayerFilterManager *pLayMan = aclyGetLayerFilterManager(pDB());
    pLayMan->getFilters(pRoot, pCurrent);

    Acad::ErrorStatus es;

    //Get and check existing filters
    const AcArray <AcLyLayerFilter*> pArrayLst = pRoot->getNestedFilters();

    for (int i = 0; i < pArrayLst.length(); i++)
        pCurrent =;
        if (_tcsicmp(pCurrent->name(), filtername) == 0) {
             flag = true;
             pFilter = pCurrent;
             acutPrintf(_T("\nLayer filter \"%s\" already exists, updating..."), pCurrent->name());

    if (flag == true)

    // if not found create filter
    if (!flag)
        pFilter = new AcLyLayerFilter();

    es = pFilter->setName(filtername);
    if (es == Acad::eOk)
        es = pFilter->setFilterExpression(filterexp);
    if (es == Acad::eOk) {
        es = pRoot->addNested(pFilter);
        es = pLayMan->setFilters(pRoot, pFilter);

    if (es == Acad::eOk && !flag)
        acutPrintf(_T("\nLayer filter \"%s\" was added and set current"), filtername );
    else if (es == Acad::eOk && flag)
         acutPrintf(_T(".\"%s\" updated and current"), filtername );
         acutPrintf(_T("\nAn error occured creating the \"%s\" layer filter"), filtername);

Title: Re: Creating Layer Filters
Post by: It's Alive! on January 16, 2007, 09:20:10 PM
that Looks Awesome! Thanks for sharing.  :-)