MicroStation: Environment Expressions

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

Introduction

This article is for MicroStation CONNECT administrators and users who want to show environment information in a DGN text element. By environment information we mean data external to the DGN file such as …

  • System Date
  • System Time
  • Computer Name
  • Computer User

There are probably other environment data that we haven't considered. Here's an example of a DGN model with some text elements that show date and time …

Text fields diplaying time and date

Be Communities

If you want to ask questions about MicroStation CONNECT, post your question to the MicroStation Forum.

MicroStation Technologies

We assemble the solution from several MicroStation CONNECT technologies including …

  • Expressions
  • Item Types
  • Text Fields

Expressions

Expressions let us extract information from various sources and perform simple computations on those data. The Named Expressions dialog lets us view, define and test an expression …

Named Expressions dialog

For example, we can obtain the current date using System.DateTime.Now(). That date is a date-time value not intended for human consumption …

07/10/2021 12:33:25

Other operations let us manipulate text. For example, we might want to format the date to something more readable using a format string …

System.String.Format ("{0:yyyy-MMM-dd}", System.DateTime.Now())

The result of that computation is easier on the human eye …

2021-Oct-07

We use the Named Expressions dialog to develop and test an expression. We use the expression in an Item Type property definition.

Item Types

Item Types let us define meta data in an Item Type library. That library can subsequently be used to create an Item instance with named properties. In this solution we create an Item Type library named Environment that contains Item Type DateTime …

Item Type Definition

DateTime has properties CurrentDate and CurrentTime. Those properties each contain an expression that obtains the system date or time and formats it as a string.

DateTime.CurrentDate

The Expression in the above dialog is not easy to see. Here it is …

System.String.Format ("{0:yyyy-MMM-dd}", System.DateTime.Now())

Once you've defined an Item Type, you can create an Item instance attached to one of three DGN objects …

  • Graphic Element
  • Model
  • File

Use MicroStation's built-in tool to attach an Item Type to a DGN element. If you want to attach an Item Type to a DGN model or file, use MicroStation Explorer.

With Explorer open in MicroStation, right-click the active DGN file, and choose Attach Item on the context menu …

Attach Item to File

Next, choose the DateAndTime Item Type in the dialog and click Attach …

DateAndTime properties

Text Fields

MicroStation Text Fields are created as part of a DGN text element. To create a Text Field, start placing some text, which opens the Text Editor dialog …

Text Editor Insert Field

Press the Insert Field button to open the Select Field Type dialog. Choose File Properties …

Text Editor Select Field Type

The Fields Editor dialog opens. Because the DateAndTime.CurrentDate and DateAndTime.CurrentTime are Expressions, they are calculated automatically. Those properties are now visible as file properties that you can use in a Text Field …

Fields Editor

Putting It All Together

Follow these steps to create a Text Field that displays a property of the DateAndTime Item Type …

  1. Start to place some text, which opens the Text Editor
  2. With the Text Editor open, click the Insert Text Field button
  3. The Select Field dialog opens
  4. Choose the File Properties option
  5. Click OK
  6. The Fields Editor dialog opens
  7. Click on the CurrentDate or CurrentTime property
  8. Click OK

Installation

You can install this solution in one of several ways …

  • Make the DGN file that contains the Item Type definition your seed file
    • Each time you create a new DGN file from that seed, the Item Type definition is included and the DGN file retains the instance attachment
  • Make the DGN file a design library (DGNLib)
    • The Item Type definition is automatically available
    • You must attach the Item Type to the DGN file as described above

Whichever you choose, you can subsequently create a text field that references the required Item Type property.

Download

Download the Date Time Expressions Example DGN File

You can download the Date Time Expressions DGN file. The DGN file was created using MicroStation CONNECT Update 16. It should work with versions of MicroStation CONNECT from Update 12.

Questions

Post questions about MicroStation to the MicroStation 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 07-Oct-2021 Copyright © 2021…2025 Jon Summers