Named Groups

MicroStation Named Groups are a useful tool. They let you manipulate a number of DGN elements that have some kind of relationship. The relationship between the elements is defined by you, the MicroStation user. Here's the Named Group dialog provided by MicroStation …

Named Group dialog

The above screenshot shows three Named Groups: Circles, Lines and Polygons. Each group has four member elements.

Named Groups — Under the Hood

A MicroStation DGN element is unaffected by its membership of a Named Group. As you know, each and every element has an ElementID that is unique within a given DGN file. A Named Group is really a collection of ElementIDs, stored in a NamedGroupElement. A NamedGroupElement is not a graphic element, and is a member of the control element cache of a ModelReference.

When you add an element to a Named Group, MicroStation copies that element's ID to the NamedGroupElement. The member element has not been modified — it doesn't mind having its identity stolen.

When a DGN element is a member of a Named Group, MicroStation's element popup information mentions the group name …

Element Named Group info

VBA Implementation

This VBA project was written to inform you about VBA's treatment of Named Groups. It doesn't do anything that MicroStation's built-in tools can't do. What it does do is to tell you about the VBA NamedGroupElement and its family members, and what you can do with them. The main feature of this macro is the user interface …

VBA Named Groups dialog

When you load the macro, it pops the above dialog and calls PopulateNamedGroups from the UserForm initialise event. PopulateNamedGroups copies the name of each Named Group to a ListBox. The ListBox shows each Named Group found in the active model.

The macro does not create any Named Group: it uses those that it finds in your DGN file.

User Interface

There are three buttons (VBA command buttons) that you can use …

If you click the Trace Elements button, the macro looks for DGN elements that are members of the selected Named Group. Information about those elements is displayed in MicroStation's Message Center.

If you click the Add Element button, the macro starts an element picker.

Element Picker

The element picker clsElementPicker is a VBA class that Implements ILocateCommandEvents. When started, using the Add Element button, that class lets the user locate an Element. Once chosen, the macro adds that element to the selected Named Group. There's some validation code in there to ensure that the element doesn't already belong to the chosen Named Group. Once the element is added, the NamedGroupElement.Rewrite method is called to persist the addition.

If you're a VBA developer, then download the macro and examine the source code using MicroStation's Interactive Development Environment (IDE).

Download NamedGroups.zip

Download the Named Groups ZIP archive, and unpack it to a suitable location such as \Workspace\Standards\macros. Start the macro using the key-in …

vba run [NamedGroups]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.