Python

Enumerate a Cell Library

A cell library is a DGN file. Usually, it has file extension .cel. Just like any other DGN file, a cell library contains models. Each model may be designated as a cell. A cell may be 2D or 3D. To read the cells from a library is the same as reading models from a DGN file.

Get Active Cell Library

First, get a reference to the active cell library file object.

We show how to obtain a cell library object reference. We wrapped that in a simple function call …

GetActiveCellLibraryObject(lib_reference)->bool

That function attempts to obtain the cell library reference for the active cell library. If successfull, it returns True and lib_reference is a valid DgnFile.

Enumerate the Cell Library object

The way to enumerate the models in a DGN file (or the cells in a cell library) is to get a ModelIndex …

model_index = lib_reference.GetModelIndex()

A ModelIndex is a collection of ModelIndexItem. We can enumerate the ModelIndex to get the details of each model (cell) in the DGN file. You can use a for loop, but here's how to do it using a Python list comprehension  …

cell_list = [model_item.GetName() for model_item in model_index if model_item.IsCell()]

cell_list is a Python list of cell names.

Download la_solutions_cell_library.zip

Unpack the ZIP file and copy the Python files into a folder that MicroStation knows about.

Python Manager

Use MicroStation's Python Manager to find and execute the script …


Questions

Post questions about MicroStation Python programming to the MicroStation Programming Forum.