Iterators
- Last UpdatedJun 02, 2022
- 1 minute read
The DBElementCollection class can be used to iterate through the database hierarchy. The iterator is created with a root element and an optional filter. There are then methods to step through the hierarchy and return the element at the current location.
For example: to look for all nozzles below a given element
TypeFilter filt = new TypeFilter(DbElementTypeInstance.NOZZLE);
DBElementCollection collection;
collection = new DBElementCollection(ele, filt);
The collection can then be iterated through using foreach
foreach (DbElement ele in collection)
{
…. Do something
}
The iterator class has been written to avoid unnecessarily scanning parts of the database that will not match the filter, for example: if looking for all boxes then the iterator will not bother to look below pipes.