Author Topic: Creating Layer Filters  (Read 2230 times)

0 Members and 1 Guest are viewing this topic.

mjguzik

  • Newt
  • Posts: 30
Creating Layer Filters
« 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 = pArrayLst.at(i);
        if (_tcsicmp(pCurrent->name(), filtername) == 0) {
             flag = true;
             pFilter = pCurrent;
             acutPrintf(_T("\nLayer filter \"%s\" already exists, updating..."), pCurrent->name());

        }
    if (flag == true)
    break;
    }

    // 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 );
    else
         acutPrintf(_T("\nAn error occured creating the \"%s\" layer filter"), filtername);
}

   

It's Alive!

  • BricsCAD
  • Needs a day job
  • Posts: 6929
  • AKA Daniel
Re: Creating Layer Filters
« Reply #1 on: January 16, 2007, 09:20:10 PM »
mjguzik
that Looks Awesome! Thanks for sharing.  :-)

Dan