DgnPlatformNet |
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.
If you want to ask about development for MicroStation, post your question to the MicroStation Programming Forum.
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#.
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.
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.
It's the job of the DGN Model Enumerator to analyse each DGN model.
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.
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 …
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.
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.
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 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 .NET projects are available. The DGN file enumerator is an AddIn named FileCollector. The DGN model enumeration is an AddIn named FileProcessor.
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 …
The controls on that dialog include …
List<Document>
Document
with a BindingSource
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;
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.
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 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.
Post questions about MicroStation programming to the MicroStation Programming Forum.