Connect Version 13 C# Programming - ScanCriteria

Hello to All, I am having issues with ScanCriteria scanning and finding elements, I have attached the code below:

Any help would be appreciated.  In vb.net coding I used the Bentley.Interop.MicroStationDGN assembly which is a different scan process. I would like to use the Bentley.DgnPlatformNET assembly in my C# programming.

Thank you, Donna Rodrick

using Bentley.DgnPlatformNET;
using Bentley.DgnPlatformNET.Elements;

namespace SheetManager
{
 public partial class CtSheetManager : Form
 {
    //other code
 

    List<BDPN.Elements.Element> scanEls = new List<BDPN.Elements.Element>();
    scanEls.Capacity = 100;
    using (ScanCriteria scanC = new ScanCriteria())
    {
        List<MSElementType> elementTypes = new List<MSElementType>
        {
            MSElementType.Text
        };
        scanC.AddElementTypes(elementTypes);
        elementTypes.Clear();

        List<DgnElementClass> classTypes = new List<DgnElementClass>
        {
	        DgnElementClass.Construction
        };
        scanC.AddClassTypes(classTypes);
        classTypes.Clear();

        scanEls = scanC.Scan(dgnModel);
    }
    
    //more code

Parents
  • I am having issues with ScanCriteria

    As Jan commented, you haven't told us your problem.  Here's an article about Model Scanning and Enumeration using .NET for MicroStation CONNECT.  Examples are provided.

     List elementTypes = new List
            {
                MSElementType.Text
            };
            scanC.AddElementTypes(elementTypes);
            elementTypes.Clear();

    .NET passes objects by reference.  You set the scanner element types and immediately clear the list.  I would be inclined to remove elementTypes.Clear().  You do similar with element classes.

     
    Regards, Jon Summers
    LA Solutions

  • Hi Jon,

    Here's an article about Model Scanning and Enumeration using .NET for MicroStation CONNECT.

    the part about using ModelElementsCollection is misleading a bit: There is (nearly never) reason to obtain Enumerator from IEnumerable<T> collection explicitly. In the discussed situation it's bad practice, because instead of simple foreach enumeration it leads to more complex code. And the performance of both (foreach and while) is usually nearly the same for List enumerables.

    Minor comment is that to use "model_" as a variable name is against C# naming conventions. And even when I am aware the conventions are not mandatory rules and everybody can define own ones, for C# these standards are well defined and followed generally (and can be checked by different assistants like StyleCop etc.). So to use anything else (e.g. to apply C/C++ naming styles to NET world as many develoeprs do)  in contraproductive at the end.

    Regards,

      Jan

  • Hi Jan,

    Thank you so much for your help!  I like the ElementPropertiesGetter, I wrote my code using GetDisplayParameters() to get class information.  I am changing it to the ElementPropertiesGetter.

    I truly appreciate the kindness of this group.

    Donna

  • Hi Donna,

    Thank you so much for your help!

    It's my pleasure ... and it did not require too much effort as I reused a code snippet from my (still growing) library of "try to understand how this piece of API works" code :-)

    To use the simple iteration is recommended by Bentley, such discussion is somewhere in this forum history.

    To use ScanCriterias is fine and more convenient for people using ScanCriteria concept in the past, but it's slower (I did some tests, but I do not remember exact results). When there are a lot of conditions and filters, the iteration could be implemented using a complex code and the performance is similar to ScanCriteria, but an advantage is it's possible to optimize exactly based on an application priorities.

    I like the ElementPropertiesGetter

    ElementPropertiesGetter and ElementPropertiesSetter are primary ways how to access an element properties.

    I truly appreciate the kindness of this group.

    Thanks :-) ... I am aware of we (me including) are not always nice, but when anybody provides own code (so it's clear he tries to do something and it's not "write code for me"), I am sure he will receive some responses from the community.

    With regards,

      Jan

  • the part about using ModelElementsCollection is misleading a bit: There is (nearly never) reason to obtain Enumerator from IEnumerable<T> collection explicitly

    You'd better inform whoever at Bentley Systems wrote the SampleECProvider delivered with the SDK.

    Bentley.DgnPlatformNET.ModelElementsCollection elementsCollection = 
        element.DgnModel.GetGraphicElements ();
    Bentley.DgnPlatformNET.ModelElementsEnumerator elementEnumerator = 
        (Bentley.DgnPlatformNET.ModelElementsEnumerator)(elementsCollection.GetEnumerator ());
    Bentley.DgnPlatformNET.Elements.Element currentElement = null;
    while (elementEnumerator.MoveNext())
    {
      currentElement = elementEnumerator.Current;
      if (!SupportsElement (currentElement))
        continue; // only process elements that are supported.
       …
    }
    

     
    Regards, Jon Summers
    LA Solutions

Reply
  • the part about using ModelElementsCollection is misleading a bit: There is (nearly never) reason to obtain Enumerator from IEnumerable<T> collection explicitly

    You'd better inform whoever at Bentley Systems wrote the SampleECProvider delivered with the SDK.

    Bentley.DgnPlatformNET.ModelElementsCollection elementsCollection = 
        element.DgnModel.GetGraphicElements ();
    Bentley.DgnPlatformNET.ModelElementsEnumerator elementEnumerator = 
        (Bentley.DgnPlatformNET.ModelElementsEnumerator)(elementsCollection.GetEnumerator ());
    Bentley.DgnPlatformNET.Elements.Element currentElement = null;
    while (elementEnumerator.MoveNext())
    {
      currentElement = elementEnumerator.Current;
      if (!SupportsElement (currentElement))
        continue; // only process elements that are supported.
       …
    }
    

     
    Regards, Jon Summers
    LA Solutions

Children