We created the MicroStationDetector in response to questions posted to the Bentley Discussion Groups, specifically the MicroStaton Programming Forum. The MicroStationDetector provides a means to perform various tasks when MicroStation is not running.
The original MicroStationDetector is a COM server written in an ancient and obsolete language: Visual Basic. It's a 32-bit DLL. A version for MicroStation CONNECT will require a new development using .NET. If you're interested in a 64-bit version for MicroStation CONNECT please contact us.
Q Here are some common questions from the discussion groups …
A The MicroStationDetector is a simple answer to those questions. It's a COM Automation server, meaning that you can reference it from any COM-compatible programming language, including VB and VBA. It has several methods and properties: for example, start MicroStation using a specified workspace; or determine a file's file type and dimension.
If you are developing a MicroStation VBA (MVBA) project the MicroStationDetector is irrelevant. In that case, you are already connected to MicroStation. The MicroStationDetector is intended for use with VB, or a VBA project in a non-MicroStation application such as Microsoft Excel.
Look at this page, which shows how to verify a file using MicroStation VBA. The code described there will not work with pure VB, which is why we created the MicroStationDetector.
The MicroStationDetector requires that MicroStation be installed on your computer. MicroStation need not be running, however, to use the MicroStationDetector: it is designed to be used to perform various tasks (defined by you) prior to starting MicroStation.
MicroStation's own Automation server has no way to specify a workspace if you create a new instance of MicroStation. In other words, if you start MicroStation from VB then you always get the default workspace, or more likely the workspace that was used the last time someone used MicroStation on your computer.
Expressed in VB language terms, here's an interpretation of the previous paragraph …
Dim oMicroStation As New MicroStationDGN.Application' Next line won't compile because a UserWorkspace property does not exist
oMicroStation.UserWorkspace = "UserWorkspaceName"
The MicroStationDetector lets you specify a …
-wu
switch-wp
switch-wd
switch -wc
switch
Once you've set the workspace names, you can call the StartMicroStation
method.
The sole argument to StartMicroStation
is a design file name.
This method returns True
once MicroStation has started and it's safe to create a MicroStationDGN.Application
reference.
The MicroStationDetector looks for ustation.exe
in the folders specified by the
Windows PATH
environment variable. When you installed MicroStation, the installation added the
C:\Program Files\Bentley\Program\MicroStation
folder to the system PATH
.
If you have modified the PATH
variable and removed the MicroStation folder, then
the MicroStationDetector won't be able to find ustation.exe
.
If you have multiple versions of MicroStation installed on your computer, the MicroStationDetector
starts the executable found first in the PATH
variable. If you have both MicroStation/J and MicroStation V8
installed on your computer, make sure that V8 occurs first in PATH
.
StartMicroStation
returns an error object containing a description and code under
these failure conditions …
ERR_MICROSTATION_RUNNING
: an instance of MicroStation is already running ERR_MICROSTATION_START
: it attempted to start MicroStation and failed
You can provide a design file name to StartMicroStation
, without
a full path specification. MicroStation will search the folders specified in the
workspace configuration variable MS_DEF
in an attempt to find the file …
You should set the user, project, database, and configuration workspaces explicitly …
Dim oDetector As New MicroStationDetector.MSDetector Dim wu As String, _ wp As String, _ wd As String, _ wc As String, _ dgnFile As String wu = "UserWorkspace" wp = "ProjectWorkspace"' Database configuration should be BUDBC, ODBC, OLEDB, or ORACLE
wd = "Database Configuration" wc = "Startup Configuration" oDetector.UserWorkspace = wu' -wu switch value
oDetector.ProjectWorkspace = wp' -wp switch value
oDetector.DatabaseConfiguration = wd' -wd switch value
oDetector.StartupConfiguration = wc' -wc switch value
dgnFile = "design.dgn" oDetector.StartMicroStation dgnFile
The MicroStationDetector also lets you enquire whether MicroStation is running. It checks the current set of
Windows processes to find ustation.exe
. Note that it cannot differentiate between
versions of MicroStation, so this property returns True
if either MicroStation/J or MicroStation V8 is running …
Dim oDetector As New MicroStationDetector.MSDetector If (oDetector.IsMicroStationRunning) Then Debug.Print "MicroStation is running" End If
The MicroStationDetector can check a file to verify whether MicroStation V8 is able to open it. You can check a file before or after MicroStation is running: in other words, you can use the MicroStationDetector to prepare a list of valid DGN files before instructing MicroStation to open them. Various properties tell you what version of MicroStation created a file, and if the file is 3D …
' Can MicroStation open this file?
Dim oDetector As New MicroStationDetector.MSDetector If (oDetector.CanMicroStationOpen ("C:\path-to-file\file.xyz")) Then' Open this file with MicroStation
End If
' Is this a MicroStation/J file?
Dim oDetector As New MicroStationDetector.MSDetector If (oDetector.IsV7DesignFile ("C:\path-to-file\file.xyz")) Then' Open this MicroStation/J file
End If
' Is this a MicroStation V8 file?
Dim oDetector As New MicroStationDetector.MSDetector If (oDetector.IsV8DesignFile ("C:\path-to-file\file.xyz")) Then' Open this MicroStation V8 file
End If
' Is this a 3D file?
Dim oDetector As New MicroStationDetector.MSDetector If (oDetector.Is3D ("C:\path-to-file\file.dgn")) Then' Open this file for 3D operations
Else' Open this file for 2D operations
End If
To use the MicroStationDetector in VB you must first install it, and then add a reference to the DLL from your VB project …
Normally, the installer will register the DLL for you. If you need to register the DLL manually as an Automation server …
MicroStationDetector.DLL
is located regsvr32 MicroStationDetector.DLL
If you are using Visual Basic, open the References dialog from the Project|Properties menu. Browse the list of Automation servers to find the LA Solutions MicroStation Detector, check the box, and click OK to finish …
Because the MicroStationDetector uses functions from MicroStation's libraries, it must be able to find
those DLLs as it loads. Like any other DLL, the MicroStationDetector asks Windows to find
MicroStation's files by examining the system PATH
variable. PATH
should
include the folder where ustation.exe
is located. Typically, this is
C:\Program Files\Bentley\Program\MicroStation
.
Unfortunately, the installer isn't clever enough to add that folder to the PATH
variable,
so you must add it manually.
You can add a folder to the system PATH
variable by right-clicking the Windows My Computer icon
and selecting the Properties menu, which pops the System Properties dialog.
Click the Advanced tab, then press the Environment Variables button. This pops the Environment Variables
dialog, where you can locate and edit the PATH
variable.
We've provided a sample VB (VB6, service pack 6) project that shows how to use the MicroStationDetector.
It pops a form with a Check button that tests whether a Windows process ustation.exe
is running.
There are text boxes for a user workspace name, a project workspace name,
a configuration workspace name, and a design file name.
Key in the workspace and file names, then press the Start MicroStation button. The VB code
invokes the StartMicroStation
function to start MicroStation
using the specified workspaces with the designated design file. The result is as if you had
specified
ustation.exe -wu<UserWorkspace> -wp<ProjectWorkspace> DgnFileName.dgn
in a Windows shortcut or command line.
The Evaluate button computes the value of a configuration variable keyed in to the CfgVar text field. The value is determined using MicroStation's current workspace settings. In other words, if you start MicroStation using this VB form, you can find the value of any CfgVar defined in the specified workspace.
The Help menu provides an About box that reveals the current version of the MicroStationDetector DLL. If you ever need to contact LA Solutions, you should provide this version number in any query about this DLL.
The MicroStationDetector is available free of charge with no warranty of fitness for purpose
and is not supported. The source code of the MicroStationDetector.DLL
is not published.
LA Solutions Ltd grants you a zero-cost license to use the MicroStationDetector for your own purposes. You may not distribute copy or sell the MicroStationDetector license to any other party.
The MicroStationDetector ZIP archive contains the
installation setup for the MicroStationDetector.DLL
and a
sample VB project with source code.
The MicroStationDetector has been developed for Windows XP. It has not been tested with Windows Vista.
Unpack the MicroStationDetector ZIP archive
to a folder of your choice, then start setup.exe
to start installation. You must register the DLL as described here.
Open the VB project and step through in debug mode to see how to use the MicroStationDetector.
The MicroStationDetector can test a file to determine whether MicroStation can edit it. Furthermore, it can tell you the version (V7 or V8) of a file and its dimension (2D or 3D). Using that information, you can then start MicroStation and open a file for editing.
Alternatively, you might want to build a list of DGN files for subsequent batch processing by MicroStation. The MicroStationDetector helps you to realise that concept, and we've even provided an example VB project. The DgnFileBrowser VB project shows how to use the MicroStationDetector to check a file chosen by a user and add that file to a list.
The DGN File Browser is sample VB code. It shows you how to use the MicroStationDetector
to verify the file type and dimension of a file chosen by a user. If the file is compatible with MicroStation,
it's added to a ListView
control as illustrated above. The DGN File Browser requires
that the MicroStationDetector be installed in order to create a reference to it.