MicroStation and Application Development

MicroStation® is a computer-aided-design (CAD) tool produced by Bentley Systems. It is used by engineers, architects, and draughting technicians to create 3D models and 2D drawings.

MicroStation can be customised. Bentley Systems themselves have many applications for specialised markets that use MicroStation as a platform. Third-parties likewise may use MicroStation as a platform on which to develop their application software. Bentley Systems provide the MicroStation Software Development Kit (SDK) that software developers use to create their applications.

The SDK has two libraries: the MicroStation Development Library (MDL) and the MicroStationAPI. The MicroStation Development Library contains thousands of functions that provide a C-language interface. The MicroStationAPI provides an object-oriented C++ interface.

While MDL has been available since 1993, the MicroStationAPI is relatively recent and ill-understood by developers. This article provides a note about the ChildElemIter class. The MicroStationAPI documentation provides no clue to the purpose of this class nor any example.

ChildElemIter class

ChildElemIter provides a way to navigate the children of complex elements such as a cell. The MDL way was to follow the next pointer in an MSElementDescr* chain. ChildElemIter exemplifies encapsulation: it lets us find the children of an element without having to know its internals.

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

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

    if (elemType == eh.GetElementCP()->hdr.ehdr.type)
    {
        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.]