The MicroStation ElementEnumerator object can be populated from a variety of sources: scan criteria, fences, selection sets, and complex elements. Once the ElementEnumerator object is set it can be used to iterate through all of the elements in the list and modify them if necessary.
Developing general purpose, reusable, routines to process ElementEnumerators can make your programs more flexible, shorten development time, and make them much easier to maintain.
The code below illustrates the different ways to build an ElementEnumerator in one routine then pass it to another for processing. The EnumerateExample Sub shows the different methods to build an ElementEnumerator. It then calls the ChangeColor sub which takes an ElementEnumerator and a color number as arguments to change the color of all the elements in the enumerator. This example can be expanded to define ElemenentEnumerators in varying modules and routines then call different routines to process for the desired result.
Sub EnumerateExample(Optional elComplex As ComplexElement = Nothing)
Dim ee As ElementEnumerator
Select Case True
' process components of a complex element if defined
Case Not (elComplex Is Nothing)
Set ee = elComplex.GetSubElements
' Use active selection set if any elements selected
Set ee = ActiveModelReference.GetSelectedElements
' Process fence contents if fence is defined
Set ee = ActiveDesignFile.Fence.GetContents
' Build EE using scan criteria
Dim es As ElementScanCriteria
Set es = New ElementScanCriteria
Set ee = ActiveModelReference.Scan(es)
' Pass the ElementEnumerator off to a different sub/function for processing
ChangeColor ee, 1
End Sub ' ' '
' This sub changes the color of all elements in the enumerator, no matter how the enumerator was created. ' It can easily be modified to change other element properties '
Sub ChangeColor(ee as ElementEnumerator, idColor as Long)
Dim elArray() as Element
Dim i as Long
Dim iStart as Long
Dim iEnd as Long
' create an element array from enumerator
elArray = ee.BuildArrayFromContents
iStart = LBound(elArray)
iEnd = UBound(elArray)
' loop through array and change color
For i = iStart To iEnd
elArray(i).Color = idColor
End SubLast Month’s Tips: Civil 3D Tip: 2D MicroStation Tip: Selecting InRoads Tip: Display VBA Tip: Pick
Measurements on 3D Objects your DWG Version References in Roadway Designer the Right Element Don’t want to miss out on other great information? Subscribe to this blog or our monthly eNewsletter now! Learn More ◊ Contact us today ◊ Newsletter ◊