Python

Named Groups

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 …

MicroStation: Named Groups dialog

Named Group Examples

Link Name Comment
List Named Groups List Named Groups Create a list of Named Groups in a DGN file
NamedGroupProxy NamedGroupProxy class Used in most examples mentioned here
Read Named Groups from JSON Shows how to read a JSON file Convert JSON to a Python list of Named Groups
Write Named Groups to JSON Shows how to write a dictionary of Named Groups to a JSON file Convert a Named Groups list to a Python dictionary, which is written to JSON

Type Hints

Python Type Hints are optional. I use them because I believe that they clarify function and method definitions. A type hint tells you what type of object to pass to a function, and what type of object that function returns. Here's an example …

def create_named_group(self, dgn_model: DgnModel = ISessionMgr.ActiveDgnModelRef)->(int, NamedGroup):

Download the Named Groups Python Projects

LA Solutions: Named Group Python Examples

The folder structure looks something like this …

├── la_solutions_export_json_named_groups.py
├── la_solutions_read_json_named_groups.py
├── la_solutions_write_json_named_groups.py
├── la_solutions_list_named_groups.py
├── NamedGroups
│   ├── common.py
│   ├── named_group_proxy.py

The executable code is in a file named something like la_solutions_xxx_named_groups.py. That code calls on classes and functions in sub-folder NamedGroups …

from  NamedGroups.common import  (  VersionInfo,
                                    collect_named_groups,
                                    named_group_collection_to_dictionary,
                                    named_group_collection_to_list,
                                 )
from  NamedGroups.named_group_proxy import  NamedGroupProxy