MicroStation .NET: Enumerating DGN Files

  • Products
  • Services
  • All Publications
  • CONNECT Publications
  • Links
  • WishList
  • LA Solutions
  • Home
LA Solutions
tel: +44 1398 361 800
DgnPlatformNet

Introduction

This article is for C# developers who want to write an application (AddIn) for MicroStation CONNECT. It describes a way to enumerate DGN files in your own AddIn.

Be Communities

If you want to ask about development for MicroStation, post your question to the MicroStation Programming Forum.

Enumerating MicroStation Files

Sometimes we want to enumerate several DGN (MicroStation) files, perhaps to extract information or to make a set of changes to each file automatically. This article describes a file enumerator AddIn written in C#.

DGN File Enumerator Concept

Those DGN files might be found in a Windows folder, or in a document management system (DMS) such as ProjectWise. Whatever the source of those files, we want to open each one, then perform the same operation on each.

Finding files with .NET is straightforward: you'll find many articles on the Internet that describe the required classes. However, we want to find only DGN files, so the code demonstrates a DGN file filter. The filter is based on the functionality described in this article. ProjectWise, as a DMS knowledgeable about MicroStation, can do something similar.

DGN File Enumerator Concept

Once each file is open, we use a DGN model enumerator to evaluate the models contained in that DGN file. We might want only to examine the default model or all models, or some models chosed through a filter.

DGN File Enumerator Concept

It's the job of the DGN Model Enumerator to analyse each DGN model.

DGN File Branding

A DGN file is branded with MicroStation workset information. That is, the workset name is included in the DGN file. When you open a DGN file with a brand that is not the current workset, MicroStation asks if you want to use that branded workset.

No Workset Alert

As a file enumerator opens each DGN file, MicroStation checks its branding. If the branded workset differs from the active workset, you will see this No Workset Alert dialog …

No Workset Alert dialog

That dialog is modal, so you must click the Open button to continue. That's a problem with automatic file processing — we want to continue opening DGN files without human intervention. One solution is to define undocumented configuration variable MS_SUPPRESS_FILE_WORKSET_ASSOCIATION, which is recognised by MicroStation CONNECT Update 15 and later. However, that may produce side-effects if the file being opened depends on its workspace resources.

Orthogonality

The file enumerator and the model enumerator both operate as MicroStation AddIns. Apart from that commonality, they are unrelated in their operation. The DGN file enumerator opens a file, then tells the model enumerator to do its job. Once the model enumerator has finished, it instructs the file enumerator to open the next file.

Consequently, we can design the file enumerator separately from the model enumerator. We define an interface to which each AddIn conforms, so that the file enumerator knows how to start the model enumerator, and the model enumerator knows, once finished, how to restore control to the file enumerator.

That approach lets us design a DGN file enumerator AddIn that gets its file list from a Windows folder, and another that solicits a list of files from a ProjectWise folder.

Similarly, the DGN model enumerator might provide an analysis or reporting tool, and a different AddIn might perform some editing.

Message-Passing

An object-oriented programming aficionado would tell you that message-passing is the way to eliminate dependencies between objects. In MicroStation, we call that technique a key-in command.

The DGN model enumerator provides a command key-in to initiate its processing. For each opened DGN file, the file enumerator sends that key-in to the model enumerator. When the model enumerator has finished analysing its models, it sends another key-in to the file enumerator to ask it to open the next DGN file.

Interface Based Programming

Interface Based Programming is a way to oblige code to conform to certain standards. In this example we design one interface in C# that defines the boundary between the file collector (Windows or ProjectWise) and the DGN file enumerator. Another interface is the boundary between the file enumerator and the model enumerator.

We also standardise the key-ins that implement the message-passing between the file enumerator and the model enumerator.

Example Implementation

Example .NET projects are available. The DGN file enumerator is an AddIn named FileCollector. The DGN model enumeration is an AddIn named FileProcessor.

File Collector

The example FileCollector obtains a list of DGN files from a specified folder. It checks each file in that folder to be sure that it is a DGN file of some kind: a design file, cell library or design library (DGNLib).

The list is presented in a dialog …

File Collector dialog

The controls on that dialog include …

  • Radio Buttons to choose the source folder
  • Button Harvest Files collects a set of DGN files in a List<Document>
  • Data Grid View shows collected files. The Data Grid View is bound to the list of Document with a BindingSource
  • Handshake Information specifies the handshake between the File Collector and the File Processor
    • Companion AddIn is the name of the file processor, in this example File Processor
    • Companion Key-In is the key-in that the File Collector sends to the File Processor
    • Handshake is the key-in that the File Processor sends to the File Collector to open the next DGN file
  • Button Process Files opens the first file in the list then starts the handshake process …
    1. Send the Companion Key-In to instruct the File Processor to work on the newly-opened file
    2. The File Processor, in this example, enumerates the models of the file, then handshakes with the File Collector
    3. The File Collector opens the next file in the list
    4. Repeat from (1)

The BindingSource class makes it easy to establish bidirectional communication betwee a List of objects and the UI view of those objects …

var bindingList = new BindingList((List<Document>)docs);
var source = new BindingSource(bindingList, null);
dataGridFiles.DataSource = source;

Form Base Class

The File Collector dialog, or .NET Form, inherits base class TopLevelForm. That base class makes it easy to integrate your form with MicroStation and to use Visual Studio to design it. This article describes TopLevelForm in detail.

File Processor

The File Processor does whatever you want with a DGN file. In this example, the File Processor AddIn enumerates the models of the DGN file and emits some information about each to the MicroStation Message Center. Its interface is defined by the handshake commands …

  • The Companion Key-In is received from the File Collector after it opens a DGN file
  • The File Processor processes the DGN file. In this example, it analyses the file's models
  • Once processing is complete, the File Processor sends the handshake command to the File Collector

Download Example Project

The Visual Studio solution and project code for the File Collector and the File Processor is available in a ZIP package. Unpack the ZIP archive and copy the source code to a suitable location.

The solution contains two Visual Studio projects: File Collector and the File Processor. When you build the solution two DLLs are created, hopefully in ..\MicroStation\mdlapps. You may need to edit the Visual Studio project settings to set the correct location on your computer.

You can load and run the File Processor by itself with key-in mdl load FileProcessor. You can copy the File Processor project and convert it for your own needs. The File Processor has no UI apart from its key-in commands.

You can load and run the File Collector with key-in mdl load FileCollector. The File Collector pops the dialog shown above.

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.


Bentley Technology Partner

Trademarks

All trademarks are acknowledged. Trademarks may be registered in some jurisdictions.
e-mail Contact LA Solutions using this enquiry form.

Home
Home
Updated on 14-Jun-2021 Copyright © 2021…2025 Jon Summers