[Connect U13] [C# | C++] mdlScanCriteria_setXAttributeTest does not look into Cells

I have a problem with the function mdlScanCriteria_setXAttributeTest mentioned by in this post:

When setting a XAttribute as a Filter, this function does not look into Cells. Same for ParametricCells but there I do not get any Information's no matter if scanning or looking directly into it, but this as a side note. Other Elements are found with that function and when not using mdlScanCriteria_setXAttributeTest I get all Elements inside a Cell (ParametricCells still doesn't work). The same code does work in V8i.

The C# Code:

BCOM.ElementScanCriteria scanCri = new BCOM.ElementScanCriteriaClass();
         mdlScanCriteria_setReturnType(scanCri.MdlScanCriteriaP(), 1 , 0 /* FALSE */, 2 /* TRUE */);
         XYZmdlScanCriteria_setXAttributeTest(scanCri.MdlScanCriteriaP(), 42 , 42);

         BCOM.ElementEnumerator num = currentModelRef.Scan(scanCri);
         BCOM.Element[] arrElemente = num.BuildArrayFromContents();

XYZmdlScanCriteria_setXAttributeTest is Wrapped and in C++, the XAttributeID gets build. Both 42s are only used for the ID and I've replaced them here.

return mdlScanCriteria_setXAttributeTest(reinterpret_cast<ScanCriteriaP>(p_ScanCriteria), &h_XAttrID, XAttributeHandle::MATCH_ANY_ID, NULL);

mdlScanCriteria_setReturnType(scanCri.MdlScanCriteriaP(), 1 , 0 /* FALSE */, 2 /* TRUE */);
gets used like this in V8i and works there. I do not know why true is a 2 but I've tried 1 also. Removing this line completely doesn't changed anything.
Just getting all Elements with a specific XAttributeID would be faster

  • It's been a few days and no Ideas? do you have an idea?

    Mit freundlichen Grüßen / Best regards
    Jean-Pierre Hundhausen

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • Hi and ,

    had brought this thread to my attention this morning to try and review and provide any feedback possible.

    From our meeting and review of this issue I find two fundamental questions/paths to pursue.

    1. Can the unpublished function mdlScanCriteria_setXAttributeTest continue to be used in CONNECT successfully as it was in V8i?
    2. Is there a new updated API available in CONNECT to recommended to replace mdlScanCriteria_setXAttributeTest?

    Fortunately I am seeing options for both; however there is the direct getting up and running with the old approach (recommended for now) and the find and recommend a new replacement CONNECT API (requires some additional exploration/investigation in order to recommend).

    So, for #1.  In our review we searched and found a few prior posts (this thread and Volker) leading to the progression to this thread and can state a couple points with a recommendation (if not current in your code):

    • 's prototype recommendation of an unpublished function for V8i - pay close attention to the last parameter type.
    • Is this unpublished function still (internally) available in CONNECT? Yes.
    • Is this unpublished function (actively) used in CONNECT? Yes. PrintFoundation and AnimCore.
    • The above also hints/answers: Does it work and Can it be used w/o crashing(?). Yes.

    From the code snip provided in this thread above (thank you), Given if all the other scancriteria is configured properly, then we have to question if the function prototype is correct - specifically the last parameter's: data type and how the value is passed.  can you confirm your function prototype and value type passed conform to this signature?

    MSCORE_EXPORT int   mdlScanCriteria_setXAttributeTest (ScanCriteriaP scP, XAttributeHandlerId* handlerId, UInt32 attrId)

    For #2 (new/replacement API recommendation).  As mentioned at this time I do not have a concrete recommendation for a replacement API, though I suspect the new e.g. XAttributeHandle, XAttributeHandler API may likely provide an effective replacement, though I would need to see if I can find or create any code snips to exercise associated setup and call backs.  I will try to place a few more cycles in on this in parallel to final preparations needed towards the MSCE SDK U14 release (sorry - no specific date I can announce yet).

    In summary, please check the function prototype to see if it helps make this unpublished function come to life again for you and I will try to find a new replacement to recommend or file an enhancement if XAttributeHandle/XAttributeHandler API is not capable of replacing mdlScanCriteria_setXAttributeTest .

    Please reply back to this thread with your results when possible.

    Thank you and HTH,

  • Hello Bob

    thank you very much for your answer. While JP will collect some code snippets, I will try to explain the problem in a different way, hopefully somewhat clearer.

    Think of a DGN file with 4 rectangles, each with an XAttribut, lets call them R1, R2, R3, R4. Let’s further consider (R3 x R4) are grouped to a cell.

    With our V8i code, we will find R1, R2, R3, R4 fast. Great thanks to mdlScanCriteria_setXAttributeTest().

    Our CE code with mdlScanCriteria_setXAttributeTest() will only find R1, R2, but not the nested R3 and R4. It also finds cells, if they have XAttributes. It seems setting this test will “optimize” the scan-process to scan only the outmost elements.

    If we just comment mdlScanCriteria_setXAttributeTest() out, the scan with the same criteria’s will find R1, R2, R3, R4, and we have to try, if they have any XAttributes. This works of course, but it is awfully slow.

    Mit freundlichen Grüßen / Best regards
    Volker Hüfner

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • Volker,

    Thank you for clarifying the current problem statement further.  Let me continue to check both paths #1 w/more priority and #2 as well.

    Thank you,

  • Hello Bob,

    Volker summed up this pretty accurate.

    I can provide a DGN with some Elements and our Code with true values as it get used by us without our own Macros and Enum
    First this gets called in C#:

             Bentley.Interop.MicroStationDGN.ElementScanCriteria scanCri = new Bentley.Interop.MicroStationDGN.ElementScanCriteriaClass();
             mdlScanCriteria_setReturnType(scanCri.MdlScanCriteriaP(), 1, 0 /* FALSE */, 2 /* TRUE */);
             Bentley.Interop.MicroStationDGN.ElementEnumerator num = modelRefIn.Scan(scanCri);
             Bentley.Interop.MicroStationDGN.Element[] arrElemente = num.BuildArrayFromContents();


    From there are 2 native Methods called, that get wrapped in C#:

         //Return Type
         [System.Runtime.InteropServices.DllImport("STDMDLBLTIN.DLL", CharSet = System.Runtime.InteropServices.CharSet.Ansi, CallingConvention = System.Runtime.InteropServices.CallingConvention.StdCall)]
          public static extern Int32 mdlScanCriteria_setReturnType(Int64 scP, Int32 returnType, Int32 oneElementOnly, Int32 nestCells);
          //XAttr Test
          public static Int32 ScanCriteria_setXAttributeTest(Int64 p_ScanCriteria, Int32 e_programm)
             return (xyzXML2Data_mdlScanCriteria_setXAttributeTest(p_ScanCriteria, e_programm));
          [System.Runtime.InteropServices.DllImport("xyz.dll", CharSet = System.Runtime.InteropServices.CharSet.Ansi, CallingConvention = System.Runtime.InteropServices.CallingConvention.Cdecl)]
          private static extern Int32 xyzXML2Data_mdlScanCriteria_setXAttributeTest(
             [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.I8)] Int64 p_ScanCriteria,
             [System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.I4)] Int32 e_programm);


    One native Method is in one of our C++ files:

            extern "C" DLLEXPORT Int32 xyzXML2Data_mdlScanCriteria_setXAttributeTest(
               Int64 p_ScanCriteria,
               Int32 e_programm)
               XAttributeHandlerId h_XAttrID(0x1701, e_programm);
               return mdlScanCriteria_setXAttributeTest(reinterpret_cast<ScanCriteriaP>(p_ScanCriteria), &h_XAttrID, XAttributeHandle::MATCH_ANY_ID, NULL);

    mdlScanCriteria_setXAttributeTest is defined in a different file.
    Removing does not change the result. You mentioned the last parameter specifically, so might this be the problem?

    extern "C" Public int mdlScanCriteria_setXAttributeTest
       ScanCriteriaP scP,
       struct XAttributeHandlerId* handlerId, // Pass NULL to clear
       UInt32 attrId, // Pass XAttributeHandle::MATCH_ANY_ID for any.
       ExtendedAttrBuf* xattrBuf // Can be NULL

    In the Array arrElement I get 4 Elements but 2 are different Elements (not one of the 2 rectangles).
    I got the IDs:
    - 58702
    - 68164
    - 72608
    - 72610

    The elements in the DGN have following IDs:
    - 72609
    - 72611
    - 72608
    - 72610

    This should sum up the Code that gets used.

    Mit freundlichen Grüßen / Best regards
    Jean-Pierre Hundhausen

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • do you have any informations?

    Mit freundlichen Grüßen / Best regards
    Jean-Pierre Hundhausen

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • Its been a while. Is there an update to this issue?

    Mit freundlichen Grüßen / Best regards
    Jean-Pierre Hundhausen

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • U14 still has the same problem

    Mit freundlichen Grüßen / Best regards
    Jean-Pierre Hundhausen

    |  AB_DATE Engineering  Software   |  ab-date.de  |

  • Its been a while. U16 still has the same problems

    Mit freundlichen Grüßen / Best regards
    Jean-Pierre Hundhausen

    |  AB_DATE Engineering  Software   |  ab-date.de  |

Reply Children
No Data