Understanding DGN File
DGN File
- DgnFile format is used by Microstation or MicroStation based applications like OpenRoadsDesigner etc.
- It is an in-memory representation of a physical file, regardless of its format.
- A DgnFile contains one or more models. One model may reference another. A DgnAttachment captures a reference between models.
- Every DgnFile holds one Dictionary Model which stores data common to all elements in file.
- Elements in Design Models refer to levels, fonts, color definitions, line styles, etc. defined in their containing DgnFile.
Classes to access Dgn File
Document
Session
- Documents are edited within a session
- Starting a session, a document and its references will be opened
- The document which is loaded is the called the Master File & the model which is displayed is called the Active Model throughout the API’s
- On file open the default views are displayed, required mdl applications loaded and other settings initialized
- Application developers can monitor events like file open events
- ISessionMgr is the C# class associated with a session
Transactions
- Enables application to save changes during a session
- Transactions are made upon elements & models
- A single Transaction is a set of modifications, adds & deletes
- Transactions are journaled and can be reversed or reinstated as a unit, this is undo/redo
- Changes are in the context of a current transaction.
- API’s exist to monitor transactions.
- ITxnManager is implemented for C#
Classes to access Models
DgnModelRef: provides access to a model that may be a direct reference to a root model or an indirect reference to an attachment model - Is base class of DgnModel & DgnAttachment.
DgnModel: represents a (root) model in memory. A DgnModel consists of:
- One or more elements
- Two ElementLists :Control ElementList and Graphic ElementList
- One or more attachments
DgnAttachment: represents an attachment from one model to another
Examples of accessing objects in DGN
DGN /DGNLib
Bentley.DgnPlatformNET.DgnFile activeDGNFile = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile();
References/Attachments
DgnAttachmentCollection dgnAttachments = Session.Instance.GetActiveDgnModel().GetDgnAttachments();
foreach (DgnAttachment dgnAttachment in dgnAttachments)
{
string referenceFileName = dgnAttachment.AttachFileName;
}
Model
Bentley.DgnPlatformNET.DgnModel activeDgnModel = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnModel();
Levels
FileLevelCache fileLevelCache = activeDgnModel.GetFileLevelCache();
Elements
ModelElementsCollection modelElementsCollection = dgnModel.GetElements();
Sheets
Bentley.DgnPlatformNET.DgnFile activeDGNFile = Bentley.MstnPlatformNET.Session.Instance.GetActiveDgnFile();
ModelIndexCollection modelIndexCollection = activeDGNFile.GetModelIndexCollection();
foreach (ModelIndex modelIndex in modelIndexCollection)
{
DgnModel dgnModel = activeDGNFile.LoadRootModelById(out StatusInt status, modelIndex.Id);
if (dgnModel.ModelType == Bentley.DgnPlatformNET.DgnModelType.Sheet)
{
}
}
Annotation
Bentley.DgnPlatformNET.DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
Bentley.DgnPlatformNET.ModelElementsCollection modelElementsCollection = dgnModel.GetElements();
foreach(Bentley.DgnPlatformNET.Elements.Element el in modelElementsCollection)
{
if(el.ElementType == MSElementType.Text)
{
Bentley.Interop.MicroStationDGN.TextElement textNodeElement = (Bentley.Interop.MicroStationDGN.TextElement)el;
}
}
Cells
Bentley.Interop.MicroStationDGN.ElementCache elementCache = Bentley.MstnPlatformNET.InteropServices.Utilities.ComApp.ActiveModelReference.GraphicalElementCache;
Bentley.Interop.MicroStationDGN.ElementEnumerator elementEnumerator = elementCache.Scan();
while (elementEnumerator.MoveNext())
{
Bentley.Interop.MicroStationDGN.Element currentElement = elementEnumerator.Current;
if (currentElement.IsCellElement())
{
Bentley.Interop.MicroStationDGN.CellElement cellElement = (Bentley.Interop.MicroStationDGN.CellElement)currentElement;
}
}
Feature Definitions
Bentley.DgnPlatformNET.DgnModel dgnModel = Session.Instance.GetActiveDgnModel();
Bentley.CifNET.SDK.ConsensusConnection con = new ConsensusConnection(dgnModel);
Bentley.CifNET.GeometryModel.SDK.GeometricModel activeGM = con.GetActiveGeometricModel();
IEnumerable<Bentley.CifNET.GeometryModel.SDK.FeatureDefinition> featureDefinitions = activeGM.FeatureDefinitions;