Introduction

The MicroStation Development Library (MDL) and MicroStationAPI provide APIs for developers wanting to create custom applications for MicroStation® from Bentley Systems. We create a MicroStation application as a DLL, written using C++ and built with the Microsoft C++ compiler and linker provided with Visual Studio.

When editing your source code, you can choose whether to use Microsoft Visual Studio, Microsoft Visual Studio Code, or one of your favourite text editors.

When building your app, you can use Visual Studio or the Bentley Systems make (bmake) tools.

ChildElemIter

This article provides a note about the ChildElemIter and ChildEditElemIter class. They help when iterating a complex element, such as a cell or complex string, that contains child elements.

Collection Enumeration Diagram

ChildElemIter and ChildEditElemIter classes

The complex chain handlers were changed in MicroStation CONNECT Edition compared to their V8-generation predecessors. They no longer expose their child elements to callers. Also, ChildElemIter no longer provides a way to navigate the children of complex elements such as a cell. It would be better to use ICurvePathQuery::ElementToCurveVector and then iterate over the CurveVector. You then won't need to write special cases for Complex Shapes/Chains, Grouped Holes, Associative Regions, etc.

The CONNECT MicroStationAPI introduces the ChildEditElemIter class. You construct a ChildEditElemIter from the EditElementHandle of the top level of a complex element. You must call IsValid on this ChildEditElemIter after constructing it. The purpose of a ChildEditElemIter is to modify component elements. Therefore, this constructor will call the Handler::ExposeChildren method on the handler, passing an ExposeChildrenReason of ExposeChildrenReason::Edit. The call to ExposeChildren could fail, since not all handlers support this expose reason. If that happens, this ChildEditElemIter will be invalid.

Example Usage

#include <DgnPlatform/ElementHandle.h>

The MicroStationAPI documentation provides this note …

for (ChildElemIter child (elHandle); child.IsValid (); child = child.ToNext ())
{
...
}

Here's an example provided by Keith Bentley on the Be Communities website. Take note of his disclaimer.

StatusInt findElementByType (ElementRefP elRef, DgnModelRefP modelRef, int elemType)
{
    ElementHandle eh (elRef, modelRef);	 //	Can also construct an ElemHandle from an MSElementDescr*

    if (elemType == eh.GetElementType ())
    {
        doSomethingWithElement (eh);
        return SUCCESS;
    }

    for (ChildElemIter child (eh); child.IsValid (); child = child.ToNext ())
    {
        findElementByType (child.GetElementRef (), modelRef, elemType);
    }

    return SUCCESS;
}

[Keith Bentley disclaimer - I just typed this code in, I didn't even try to compile it.]

Back to the Iterator main page.

Questions

Post questions about C++ and the MicroStationAPI to the MicroStation Programming Forum.