Questions similar to this appear on the Be Community Forums. This topic was raised in the MicroStation Programming Forum.
Q How do I …
A A MicroStation cell element is a particular form of a MicroStation complex element. It is used to group a set of graphic elements. Those elements usually describe a 3D or 2D construct. See the section about complex elements below.
For information about scanning for cells, read article Scanning a Model for Named Cell using VBA.
A MicroStation complex elements have a linked-list data structure.
They are built in MicroStation by internal logic that uses C-style pointers and memory allocation. That model does not lend itself to VBA, which supports neither pointers nor dynamic memory management. Rather, Bentley Systems have written a VBA interface that interprets the underlying linked-list in a way that is compatible with VBA.
MicroStation VBA provide an interface ComplexObject
.
VBA element classes that implement ComplexObject
include …
ComplexShapeElement
ComplexStringElement
TextNodeElement
CellElement
SharedCellElement
SharedCellDefinitionElement
Each of the above element classes provides methods Drop
and GetSubElements
.
Both return an ElementEnumerator
object, which is a collection of elements.
See VBA help for details.
See below to find how to use an ElementEnumerator
object.
Some element types, while they might appear complex, do not implement the ComplexObject
interface.
They include all types of B-spline elements and mesh elements.
Their data structures are not implemented as linked lists, and are termed compound elements.
The ElementEnumerator
class is straightforward to use.
It enables you to move through the linked-list of component elements in a complex element.
Here's an example …
Sub ExamineCell (ByVal oCell As CellElement)
Dim oComponents As ElementEnumerator
Set oComponents = oCell.GetSubElements
Do while oComponents.MoveNext
Dim oComponent As Element
Set oComponent = oComponents.Current
' Do what you want with oComponent here
Loop
End Sub
It's not unusual for a complex element to contain another complex element. The contained complex element is nested in the parent complex element.
When analysing nested complex elements, it's common to write recursive code that digs down through the hierarchy. Here's an outline example. Note that the code works with any sort of complex element, not only cells …
Sub ExamineComplexElementRecursively (ByVal oParent As ComplexElement) Dim oComponents As ElementEnumerator Set oComponents = oParent.GetSubElements Do while oComponents.MoveNext Dim oComponent As Element Set oComponent = oComponents.Current If oComponent.IsComplexElement Then ' Here's where we get recursive ExamineComplexElementRecursively oComponent.AsComplexElement Else ' Do what you want with graphic element oComponent here End If Loop End Sub
"How do I use ExamineComplexElementRecursively
?", I hear you ask.
You might have located a complex element by scanning a DGN model, or
by asking a user to locate an element.
Either way, your code will receive something,
such as a cell or a complex shape,
that implements the ComplexElement
interface.
Just call ExamineComplexElementRecursively
, passing that object …
Sub YourModelScanMethod () Dim oCell As CellElement Set oCell = YourCellScanMethod ' Get cell from somewhere ExamineComplexElementRecursively oCell ... Dim oShape As ComplexShapeElement Set oShape = YourComplexShapeScanMethod ' Get complex shape from somewhere ExamineComplexElementRecursively oShape ... ' And so on End Sub
Some nested elements are not intended for perusal: they are opaque, and we can't see some or all of their contents. An example of an opaque element is a SmartSolid. A SmartSolid is a cell, and contains one or two graphic elements that are used to display the object as a wireframe. The essential information about the 'smartness' of a SmartSolid element is buried inside its boundary representation (BREP) data.