The MicroStation Development Library (MDL) and MicroStationAPI provide APIs for developers wanting to create custom applications for MicroStation® from Bentley Systems. We create a MicroStation application as a DLL, written using C++ and built with the Microsoft C++ compiler and linker provided with Visual Studio.
A Text Table seed is a DGN model that contains a single TextTableElement
and no other elements.
To find Text Table seed, you must enumerate the models in one or more DGNLibs.
On the Iterators main page I provide an introduction to
the various enumerators and iterators available to the C++ programmer in the MicroStationAPI.
Here, I'll focus on ways to enumerate the DGN models contained in a DGNLib (design library) to find
instances of
Text Tables
(C++ TextTable
).
A TextTable
stored in a DGNLib is a seed
Text Table.
If you want to enumerate models in a design library (DGNLib) then you must do a little more work than is is required for the active DGN file. A DGNLib is not an active file or reference, and its model collection is not necessarily loaded when you visit it in your code. In Bentley developer terminology, its caches are not filled. Consequently, you must ensure that its models are at least partially loaded when you examine them.
The following example will enumerate models found in a DGN file, whether that file be the active DGN file or a DGNLib …
#include <DgnPlatform/DgnFileIO/dgnitemindex.h>
void EnumerateModels (DgnFileP pDgnFile)
{
const bool FillCache {true};
const bool LoadRefs {true};
const bool ProcessAffected {true};
for (ModelIndexItemCR item: pDgnFile->GetModelIndex ())
{
ModelId modelId {item.GetModelId ()};
StatusInt status {0};
DgnModelP model = pDgnFile->LoadRootModelById (&status, modelId, FillCache, !LoadRefs, !ProcessAffected);
ModelInfoCP pInfo = model->GetModelInfoCP ();
if (IsTableSeed (model))
{
// ... do something with text table seed
}
}
}
A DGN model is a TextTable
seed if it contains exactly one DGN element and that element is a TextTableElement
.
Here's the code that implements that test …
bool IsTableSeed (DgnModelP model) { bool isTableSeed {false}; const UInt32 nElements = model->GetElementCount (DgnModelSections::GraphicElements); if (1 == nElements) { if (nullptr != model->GetGraphicElementsP ()) { PersistentElementRefList const* elemList = model->GetGraphicElementsP (); for (PersistentElementRefP const& elemRef: *elemList) { ElementHandle eh {elemRef, model}; TextTableHandler* handler = dynamic_cast<TextTableHandler*>(eh.GetDisplayHandler()); isTableSeed = nullptr != handler; } } } return isTableSeed; }
The above functionality is implemented in class TextTableHelper
.
You can
download the source code
(header & implementation files).
Post questions about C++ and the MicroStationAPI to the MicroStation Programming Forum.