Introduction

Questions similar to this appear on the MicroStation Programming Forum.

Often we have a worksheet or other source of point coordinates that we want to place automatically as DGN elements in MicroStation. For example, a utility might have data about Pole locations. The source of those data is often an Excel worksheet. MicroStation can import points from a CSV file, using the XYZ Text tool.

When a DGN element is tagged with business data it becomes a feature. A text element or a cell element becomes a point feature. What MicroStation can't do automatically is to make a point feature by creating a DGN element at a specified coordinate and then tagging that element with business data.

Suppose your worksheet of coordinate data has other information for each object. You want to tag the DGN element with that information. One way is to define a MicroStation CONNECT Item Type that has a set of properties that match your point data.

The MicroStation VBA macro described here performs several tasks after reading data from a CSV file …

CSV Example

Here's some example data from a CSV file …

Caption, ID, X, Y, Z, Owner, "Install Date"
"Pole 1", 1001, 10, 20, 0, "Utility 1", 01-Jan-2010
"Pole 2", 1002, 110, 22, 0, "Utility 1", 02-Jan-2010
"Pole 3", 1003, 210, 24, 0, "Utility 1", 03-Jan-2010

You can create a CSV file manually, using a text editor such as Windows Notepad. Alternative, Office applications, including Microsoft Excel, can create a CSV file from the contents of a worksheet.

The first row of the file is termed the header row. It provides each column with a name. Names that contain a space are quoted (i.e. write Install Date as "Install Date").

Remaining rows in the CSV provide data. In the above example there are three data rows. The data in each column corresponds to the name in the header row.

VBA Utility: Point Feature Loader

Point Feature Loader dialog

A DGN element becomes a feature when we have both visible geometry and business data attached to it. In this example, a Point Feature is a DGN cell or text element with attached Item data.

Q You have an Excel worksheet of point feature coordinates and Item Type values. You want to place those features and tag them with Item data …

A You can use MicroStation's built-in XYZ Text tool to place DGN text or cells at coordinates specified in a CSV file. However, MicroStation's tool won't tag those DGN elements with Item data. The macro described here will both place a DGN element and tag it with Item data.

A The VBA macro described here creates a DGN element and then goes on to tag that element with Item data. It uses the data found in a CSV file. You can write a CSV file from your Excel worksheet.

Understanding the CSV Example

The CSV Example above illustrates how to pass Item Type properties in the CSV header. What the CSV doesn't provide are …

The VBA macro shows those in its UserForm …

Point Feature Loader dialog
Item Type Definition

Click the Create Definition button to create your Item Type. The macro creates an Item Type Library (in this example, LA Solutions), and a definition for the Item Type (in this example, Utilities).

Property Definitions

The names of the properties are gathered from the CSV header row. Columns for coordinates (X, Y and Z) are ignored. In this example, the Item Type properties are named Caption, ID, Owner and Install Date.

Load CSV Data

Click the Browse button to locate your CSV file.

Click the Load Data button (labelled ...) to tell the macro to read the CSV file and create DGN elements. You can choose to create a text element that shows the Caption value, or a cell element.

Once the DGN element is created, the macro proceeds to attach the Item instance and its property data. You can see the Item properties using MicroStation's Element Property tool (Control-I) …

Item Properties

Report Example

With the CSV data attached to DGN element, you can query and report those data using MicroStation tools. Here's an example Report showing the DGN Item data on each of the three poles created from the CSV above …

Utilities Report

Guide to Reports

We provide a step-by-step guide to creating a cell report and a text report.


Download

Download Example VBA Project

A sample project is available. It includes code similar to that above and the VBA UserForm shown above. The macro is provided as freeware. It is not formally supported software. Use at your own risk.

You can download a ZIP file, and then extract PointFeatureLoader.mvba to a folder that MicroStation can find. A good place to put it would be ..\Workspace\Standards\macros, or any other folder specified in the MS_VBASEARCHDIRECTORIES configuration variable.

Start the macro with this MicroStation key-in …

vba run [PointFeatureLoader]modMain.Main

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.