Named Groups provide a way for a MicroStation user to connect logically a set of MicroStation graphic elements. Named groups can include elements from the active file and those from directly attached references. Elements in a named group can be manipulated collectively: read MicroStation help for more information. The MicroStation user interface makes it easy to create a named group and add and remove elements in that group …
As well as individual named groups, you can create a hierarchy of them by adding “child” named groups to a “parent”. When you have a hierarchy, manipulating the “parent” named group will include any attached “child” named groups. You can add and drop elements from individual named groups (including those that are part of a hierarchy), as well as manipulate the elements within each named group (again, including those that are part of a hierarchy).
Get the named groups collection for a specified DGN model like this …
dgn_model: DgnModel = ISessionMgr.ActiveDgnModelRef named_groups = NamedGroupCollection(dgn_model)
Enumerate that collection to see each named group …
count = 0
for i, group in enumerate(named_groups):
msg += f" [{1 + i}] Name: {group.GetName()}, Description: {group.GetDescription()}\n"
count = i + 1
You can create, modify, and delete named groups using the Python API.
You can visit members of a named group using the
TraverseMembers() and TraverseRelatedMembers()
functions.
Get the size of a named group like this …
n_groups = len(list(named_groups))
If you take this reasonable step and then attempt to enumerate the resulting list,
it won't work.
Something happens in the conversion and the data become garbled …
dgn_model: DgnModel = ISessionMgr.ActiveDgnModelRef
named_groups = NamedGroupCollection(dgn_model)
named_group_list = list(named_groups)
for group in named_group_list:
name = group.GetName() # Gives odd error message
There are two sets of flags that control how named groups and members of named groups may be copied or propagated …
NamedGroupFlags: The NamedGroupFlags structure holds settings for the NamedGroup as a whole.
The members are public and can be manipulated directly
NamedGroupMemberFlags: The Flags stored for each member of a NamedGroup.
The members are public, so they can be manipulated directly.
Use
NamedGroupFlags
when you create a named group.
NamedGroupFlags() instantiates a new NamedGroupFlags with default values of false for
allowDuplicates, exclusiveMembers, allowFarReferences, closed, selectMembers, and anonymous …
flags = NamedGroupFlags()
Use
NamedGroupMemberFlags
when you add members to a named group.
NamedGroupMemberFlags() instantiates a new NamedGroupMemberFlags with default values …
flags = NamedGroupMemberFlags()
Call AddMember() to add a new element to a named group.
The new member is granted the default NamedGroupMemberFlags.
GetFlags() and SetFlags() give you the option to change flags later.
The Python API documentation for the named group flags omits essential information: the flags themselves are not documented. As revealed on the MicroStation Programming Forum, you can ask Python to reveal the documentation in the source code. Thanks to Bentley Systems staffer YongAn Fu for helping with that missing information.
The flag names differ slightly from their source in the C++ MicroStationAPI …
# NamedGroupFlags
AllowDuplicates
AllowFarReferences
Anonymous
Closed
ExclusiveMembers
SelectMembers
# NamedGroupMemberFlags
BackwardPropagate
ForwardPropagate
GroupPropagate
Post questions about MicroStation programming to the MicroStation Programming Forum.