Tutorial: Including the Date in Print Output File Names

(This topic applies to MicroStation 8.11 and later.)

In this article I am going to present a step-by-step approach to including the current date (in the format dd-MM-yy) as a prefix in print output file names produced by both Print Organizer and the single-Print dialog. Note that there are multiple ways of going about this, and what I'm going to show here isn't necessarily the easiest method. However, the technique I'll demonstrate should give you a taste of the power and flexibility of expressions in MicroStation. This simple example may also make it easier for you to understand the relevant sections of the product documentation.


Like Batch Print, Print Organizer uses a pattern to determine the print output file name for each print definition in the set. In Batch Print, this pattern was typically composed of literal strings, environment variable references, and token replacements such as %p. In Print Organizer, the equivalent pattern is called an "expression", using a concept introduced in MicroStation 8.11. Although the syntax is quite different from a Batch Print pattern, expressions may also consist of literal strings, environment variable references, and token replacements. In an expression, the tokens are called "symbols", and are much more powerful that the Batch Print percent tokens.

An expression (the pattern itself) can be saved in a design library (.dgnlib) with a unique name. A saved expression with a name is referred to as a "named expression". I'm being precise with my terminology here because Print Organizer also allows use of unnamed expressions that are not stored in design libraries.

To understand expressions in MicroStation, you should read the "Named Expressions" section in the documentation, under "Programmed Customizations". What I'm going to show here just scratches the surface of what you can do with expressions.

I want to point out that Print Organizer has the ability to include the date in the print output file name without forcing you to define your own named expression. However, the date format for this default capability is yyyyMMdd. Everyone has their own preference for date formatting, and it's the flexibility of expressions that allows everyone to get the format they want.

Defining the Named Expression

The first step is to open the design library (.dgnlib) in which you can create a named expression for use by either Print Organizer or the single-Print dialog. This .dgnlib should be available in all of the workspaces from which you will be printing. You might pick a .dgnlib global to your site, a project-specific .dgnlib, or perhaps a .dgnlib referenced only by your user workspace. You could create a named expression in each .dgn file if you like, but that would not be very practical.

After opening the .dgnlib, open the Print dialog. This step is necessary for the PrintSet and PrintDefinition symbols to show up in the Named Expressions dialog later.

Select the "Utilities / Named Expressions" menu item to open the Named Expressions dialog. Select the "New" icon in the toolbar, and enter "PrintFileName Date-Design" in both the "Internal Name" and "External Name" fields. (You can choose your own name if you like).

In the Keywords list, check the "Print Set" checkbox. This indicates the expression is usable by the printing system. Otherwise, Print Organizer will ignore the expression.

In the combo box to the right of the list box under "Required Symbol Sets", select System.DateTime and then pick the Add button. Repeat for "System.String", "System.Path", "PrintDefinition", and "PrintSet" symbol sets.

In the Expression field, carefully enter the following string (quotes are literal; do not insert any newlines):

System.String.Format ("{0:dd-MM-yy}", System.DateTime.Now()) & "-" & System.Path.GetFileNameWithoutExtension (PrintDefinition.SourceFile)

The value of this expression will be the current date (in dash-separated, two-digit, day-month-year format) followed by a dash, followed by the base design file name associated with the print definition currently being printed.

A discussion of the above expression syntax and the symbols being used is well out of scope for this tutorial. Suffice to say, there is much more you can do here. For more information, please refer to the product documentation. You can also study the various expressions displayed in Print Organizer's "Default Print Definition Name Expression" and "Output File Name Expression" dialogs for more examples.

Select the "Test" button.  If you have entered the expression correctly, you will get output to the right of the button showing the value of the expression using sample input data.  If the expression is invalid for any reason, you will receive the string "Can not evaluate expression".

Select the Save icon on the toolbar. The dialog should now look like this:


Exit the Named Expressions dialog, then save and close the .dgnlib file.

Using the Named Expression in Print Organizer

If you are unfamiliar with Print Organizer, I recommend reading the "Print Organizer" section in the documentation under "Working With Complete Designs / Printing" to get an overview of the application. In particular, the "Defining Print Definition and Output File Name Expressions" section under "Print Organizer" describes how named expressions can be used to produce the print output file names.

With any design file open in MicroStation, select "File / Print Organizer". In Print Organizer's menu, select "File / Printer Setup...". Select the Browse icon, then pick pdf.pltcfg (or any other printer driver configuration that prints to file). Select OK to get back to the main Print Organizer window. Select "File / Add Files to Set...". Select Add, then use the file picker to select the design file you wish to print. Select OK, then wait for the print definition to be created.

From Print Organizer's menu, select "File / Output File Names...". Expand the combo box labeled "Expression name" and scroll to the bottom. You should see the following:

This list is separated into three sections. The top section lists all of the default expressions built into Print Organizer. The second section lists all of the named expressions found in the configured design libraries, including the one you just created. The third section is "Custom", which allows you to create an unnamed customized expression stored only in this print set (.pset) file.

Note that the list of default expressions has entries that include the current date, all using the format yyyyMMdd The purpose of this tutorial is to show you how to additional expressions using a different date format. When creating a new expression, instead of creating the expression string from scratch, you may find it easier to start with one of the standard Print Organizer expressions and modify it as needed.

Select "PrintFileName Date-Design". You'll see the expression you entered previously show up in the Expression field. Select the "Preview Names..." button. A dialog will pop up showing you output file name that will be created for each print definition in the set.


Dismiss this dialog, and press OK on the "Output File Name Expression" dialog to accept the change and return to the Print Organizer main window.

To force Print Organizer to use your named expression for the print output file names of all new print sets you create, you can define the configuration variable MS_PLT_DEFAULT_OUTPUT_FILENAME_EXPRESSION to be the name of your expression. For example,


Using the Named Expression in the single-Print dialog

So far I've only talked about printing from Print Organizer. MicroStation has a different scheme for defining the default print output file name in the single-Print dialog, through the "Default Print File Name" property in the printer driver configuration file. You can refer to a named expression in this property value, which is one way of including a customized date format in the print file output file.

To do this, open the single-Print dialog, select the printer driver configuration file you wish to modify, then select File / Edit Printer Driver Configuration. Under the Base Properties tab, scroll down to the "File Name" row in the "Default Print File Name" category. Change the value to "$(MS_PLTFILES)<expr?name=PrintFileName Date-Design>" (do not include the qoutes in the property value).


(Edit: the screenshot above does not include the reference to $(MS_PLTFILES).  Specifying the directory in the printer driver configuration file's Default Print File Name property is optional.  It's unnecessary if the Print dialog will be prompting for the final ouput file location.  However, if "Auto Overwrite File' is set to True, thus suppressing the Print dialog's output file picker, then it's important that you specify both the directory and the file name in the .pltcfg Default Print File Name.)

The special <expr?...> syntax, similar to the syntax used by the <autoInc> token, indicates that you wish to use the value of the specified named expression as the print output file name from the single-Print dialog. As with Print Organizer, the named expression must be defined in one of the design libraries configured for your workspace.

The <expr> token may also be used in pen table text substitution and print border text.  That is a topic for another day.