Before looking for a cell library, we must know its name.
If we want to see the active cell library, then look in the active DGN file using
Cell.GetLibraryName().
That function puts the file name in a
BeFileName
object that you supply.
If there is no active cell library, then the name is empty. If a cell library is attached, we can get its name …
from MSPyBentley import *
from MSPyDgnPlatform import *
from MSPyMstnPlatform import *
lib_name = BeFileName()
Cell.GetLibraryName(lib_name)
if lib_name.IsEmpty():
print("Cell Library name is empty")
else:
# Use the file name
pass
We're going to call
Cell.GetLibraryObject().
Unfortunately, its documentation is incomplete:
it tells us that it returns a tuple but without telling us the contents of that tuple.
I believe that the returned value is (error_code, library_object_reference) …
(err_code, lib_reference) = Cell.GetLibraryObject(lib_name, False)
The second bool argument is redundant and can be ignored.
If err_code is zero (eSUCCESS) then the call succeeded and lib_reference is a
valid reference to a DGN cell library file object.
I've packed the above logic into two functions …
GetActiveCellLibraryObject(lib_reference: DgnFile) that returns True
if the active DGN file has a cell library attached
EnumerateCellLibrary(lib_reference: DgnFile) that returns a Python list of cell names in that library
If you're interested in enumerating the cells in a library, then here's how.
The code is available in a single Python source file. Unpack the ZIP file and copy the Python files into a folder that MicroStation knows about.
Use MicroStation's Python Manager to find and execute the script …
Post questions about MicroStation Python programming to the MicroStation Programming Forum.