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
public partial class CtSheetManager : Form
List<BDPN.Elements.Element> scanEls = new List<BDPN.Elements.Element>();
scanEls.Capacity = 100;
using (ScanCriteria scanC = new ScanCriteria())
List<MSElementType> elementTypes = new List<MSElementType>
List<DgnElementClass> classTypes = new List<DgnElementClass>
scanEls = scanC.Scan(dgnModel);
Donna Rodrick said:I am having issues with ScanCriteria
What your issue is? You posted some code, but you did not explain what it does not do and what you want to achieve.
BTW When you need to scan elements using simple filter, it's better (and probably faster) to iterate element cache directly using ModelElementsCollection.
Labyrinth Technology | dev.notes() | cad.point
I am trying to scan the dgnModel for text that has the Construction class. I know that my test dgn has those types of elements, but the scan result list (scanEls in my code) is empty.
Does my code look correct?
I will try the ModelElementsCollection in my program.
Donna Rodrick said:I will try the ModelElementsCollection in my program.
Not tested (only that it can be compiled ;-):
DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
ModelElementsCollection graphicElements = dgnModel.GetGraphicElements();
List<TextElement> texts = new List<TextElement>();
foreach (Element el in graphicElements)
if (el is TextElement)
ElementPropertiesGetter properties = new ElementPropertiesGetter(el);
if (properties.ElementClass == DgnElementClass.Construction)
texts.Add(el as TextElement);
Donna Rodrick said: 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
.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
Jan Šlegr said:Not tested
I found few minute to test it and it works :-)
Jon Summers said: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.
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 Rodrick said: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.
Donna Rodrick said:I like the ElementPropertiesGetter
ElementPropertiesGetter and ElementPropertiesSetter are primary ways how to access an element properties.
Donna Rodrick said: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.
Jan Šlegr said: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 =
Bentley.DgnPlatformNET.ModelElementsEnumerator elementEnumerator =
Bentley.DgnPlatformNET.Elements.Element currentElement = null;
currentElement = elementEnumerator.Current;
if (!SupportsElement (currentElement))
continue; // only process elements that are supported.