DgnPlatformNet |
This article is for C# developers who want to write an application for MicroStation CONNECT. It describes a way to use DGNLib data in your own app. This is not a complete application: rather, it describes what might otherwise be a non-intuitive approach to solve a problem.
A MicroStation configuration often stores libraries of data in read-only design libraries, also known as DGNLibs. A set of DGNLibs is usually available as part of a MicroStation workspace. An administrator will often allocate different DGNLibs to store different kinds of data: for example, text styles, levels, dimensions etc. This article discusses table seeds that are stored in a DGNLib.
Because those data are stored independently of a user's active DGN file, your app may want to copy data from a DGNLib. This example shows how to harvest DGNLib data programmatically for use in your own .NET app.
If you want to ask about development for MicroStation, post your question to the MicroStation Programming Forum.
MicroStation CONNECT Edition provides Tables.
A MicroStation administrator might include several table seeds in a DGNLib. The seeds are available to a MicroStation operator via a menu, which is available while using the Tables user interface.
A table seed is a DGN model that contains a single DGN element.
That element must be a table, a TextTableElement
in programmer-speak.
An administrator would presumably design one or more tables and place them in a DGNLib. The name of the model is the name of the seed.
You want, as a MicroStation developer, to examine the visible DGNLibs and extract information about table seeds. Here's the code …
public int GetTableSeedModels ()
{
int nModels = 0;
DgnLibIterator iterator = new DgnLibIterator(DgnLibSelector.ElementStyles);
foreach (DgnFile lib in iterator)
{
// Examine each DGN model in the file
var indices = lib.GetModelIndexCollection();
foreach (var index in indices)
{
StatusInt status;
DgnModel model = lib.LoadRootModelById(out status, index.Id);
if (IsTableSeed(model))
{
string s = $"Table seed: {lib.GetFileName ()}.{model.ModelName}";
MessageCenter.Instance.ShowMessage(MessageType.Debug, s, s, MessageAlert.None);
++nModels;
}
}
}
return nModels;
}
Method IsTableSeed
is straightforward: it has to count the number of elements in a DGN model and,
if it finds exactly one, test whether that element is a TextTableElement
…
bool IsTableSeed(DgnModel model) { var elements = model.GetGraphicElements(); return (elements.Count() == 1 && elements.First() is TextTableElement); }
This article was written as a summary of my own experience in developing the DGNLib Harvester. I was helped on my way by hints & tips on the MicroStation Programming Forum. Special thanks go to YongAn Fu, a regular contributor to Bentley Communities, for his suggestions.
Post questions about MicroStation programming to the MicroStation Programming Forum.