[Connect | V8] [C# | C++ SDK] Finding Xattributes quickly and selectively, without the detour via "search element"?

To work with Xattributes, you need an ElemendHandle whether you work in managed or native code.

 

But what will be best practice to find some elements in such a case:

  • DGN with some several thousand elements
  • Some 3% elements with Xattributes
  • Some 20% of these have an interesting XAttributeHandlerId

The typical workflow: “scan for elements” -> “test for X-Attributes” -> “find XAttribute with XAttributeHandlerId” -> “analyses X-Attributes” will take its time.

 

Would it not be much faster, to scan through the Xattributes-cache for fitting XAttributeHandlerId?

Parents
  • We use this to find all the elements with a particular xattributeID.

    ScanCriteria                *pScanCriteria = NULL;
                ScanArgs                    scanArgs;
                DgnModelRefP modelRef = ISessionMgr::GetActiveDgnModelP();
                
                memset(&scanArgs, 0, sizeof(scanArgs));
    
                if (NULL != (pScanCriteria = mdlScanCriteria_create()))
                {
                   scanArgs.modelRef = modelRef;
                   
                   mdlScanCriteria_setReturnType(pScanCriteria, MSSCANCRIT_ITERATE_ELMREF, FALSE, FALSE);
                  
                   XAttributeHandlerId id = XAttributeHandlerId(XYZID, 0); //need to use your details here...
                   mdlScanCriteria_setXAttributeTest(pScanCriteria, &id, XAttributeHandle::MATCH_ANY_ID, NULL);
                   scanArgs.id = id;
                   mdlScanCriteria_setElemRefCallback(pScanCriteria, (PFScanElemRefCallback)getElementScanCallback, &scanArgs);
    
                   mdlScanCriteria_setModel(pScanCriteria, modelRef);
    
                   mdlScanCriteria_scan(pScanCriteria, NULL, NULL, NULL);
                   mdlScanCriteria_free(pScanCriteria);
                }

    Then your iterator callback will get each of the elements that meet the xattribute id.  I know it does not avoid the scan thing but is has bee quick enough for us.

    HTH,

    marka

    Answer Verified By: Volker Hüfner 

Reply
  • We use this to find all the elements with a particular xattributeID.

    ScanCriteria                *pScanCriteria = NULL;
                ScanArgs                    scanArgs;
                DgnModelRefP modelRef = ISessionMgr::GetActiveDgnModelP();
                
                memset(&scanArgs, 0, sizeof(scanArgs));
    
                if (NULL != (pScanCriteria = mdlScanCriteria_create()))
                {
                   scanArgs.modelRef = modelRef;
                   
                   mdlScanCriteria_setReturnType(pScanCriteria, MSSCANCRIT_ITERATE_ELMREF, FALSE, FALSE);
                  
                   XAttributeHandlerId id = XAttributeHandlerId(XYZID, 0); //need to use your details here...
                   mdlScanCriteria_setXAttributeTest(pScanCriteria, &id, XAttributeHandle::MATCH_ANY_ID, NULL);
                   scanArgs.id = id;
                   mdlScanCriteria_setElemRefCallback(pScanCriteria, (PFScanElemRefCallback)getElementScanCallback, &scanArgs);
    
                   mdlScanCriteria_setModel(pScanCriteria, modelRef);
    
                   mdlScanCriteria_scan(pScanCriteria, NULL, NULL, NULL);
                   mdlScanCriteria_free(pScanCriteria);
                }

    Then your iterator callback will get each of the elements that meet the xattribute id.  I know it does not avoid the scan thing but is has bee quick enough for us.

    HTH,

    marka

    Answer Verified By: Volker Hüfner 

Children