Printing with MicroStation

MicroStation®, like most applications for a PC, lets you print. As a CAD program, MicroStation printing encompasses a huge range of devices, ranging in capabilities, quality and size of output. MicroStation is produced by Bentley Systems, Inc.

Printer Devices

Examples of the types of output device include, but are not limited to, the following …

This article about printer enumeration may be useful.

For more information, consult MicroStation help. You may find the Be Communities MicroStation Printing Forum useful.

Print Control

MicroStation CONNECT provides three types of print control …

  1. VBA Printing API
  2. Print Dialog
  3. Print Organizer

MicroStation's Print Dialog has evolved over decades to provide a comprehensive interface to virtual and physical print devices. The Print Dialog lets you choose either a printer driver from Bentley Systems, or a Windows printer.

MicroStation's Print Organizer enables batch printing along with storage of print settings for each batch job. It lets you define a print style that groups your settings into one file.

Automating Print Control

Both the Print Dialog and Print Organizer have a user interface. Additionally, they both respond to command keyins. A keyin is something that you type into MicroStation's keyin dialog. If you can enter a keyin by hand, then you can automate printing by putting multiple keyins into a VBA macro.

For more information, consult MicroStation help. You may find the Be Communities Printing and Plotting Forum useful.

Printing with MicroStation VBA

Q

How can I code MicroStation VBA to control printing? MicroStation CONNECT, from Update 10, introduced a printing API.

With previous versions of MicroStation we had to use key-ins to control the PLOTDLG built-in print application. Specifically …

Questions similar to these, posed by MDL and VBA developers, appear on the Bentley Discussion Groups, typically the MicroStation Programming Forum.

Printing with MicroStation V8 VBA

If you are writing VBA for MicroStation V8, then look at this article .

Q How can I find what keyins are available?

A First, consult MicroStation help. There are chapters about Print Dialog and Print Organizer. Some sections cover the available keyins and provide examples.

MicroStation's keyin browser lets you see what commands are available for a given application …

The application behind the Print Dialog is PLOTDLG.ma. You can see its keyins by opening the MDL dialog and clicking the Browse button to find that file. You'll find PLOTDLG.ma in the \mdlsys\asneeded folder. Or, you can load it manually using the keyin
mdl load PLOTDLG

The Print Organizer application for MicroStation CONNECT is bentley.printorganizer.dll, which you can find in the \MicroStation\assemblies folder. you can load it manually using the keyin
mdl load bentley.printorganizer.dll

MicroStation VBA Print API

MicroStation CONNECT Update 10 introduced a print API. VBA provides the following classes …

Look in the VBA help document topic IPrintEvents for examples of the print API.

Print Information

Robert Arnold, a frequent contributor to the MicroStation Programming Forum, posted some useful information about printer internals on that Forum.

When a MicroStation application, such as the Plot Dialog, is loaded, it may publish a set of application variables. If published, we can determine their value by using the C expression interpreter, implemented by the VBA GetCExpressionValue() function. For example, plotUI is the variable published by the plot dialog, and it contains several members such as plotUI.uiSysPrinterName which contains the currently selected Windows printer name. For example …


' ---------------------------------------------------------------------
'   TracePrinterSettings
'   Get Print Dialog settings from its published application variable
'   plotUI
' ---------------------------------------------------------------------
Sub TracePrinterSettings()
  CadInputQueue.SendCommand "DIALOG PLOT "
  Debug.Print "Printer Name: "       & GetCExpressionValue("plotUI.uiPrinterName")
  Debug.Print "Windows Printer: "    & GetCExpressionValue("plotUI.uiSysPrinterName")
  Debug.Print "Paper Tray: "         & GetCExpressionValue("plotUI.uiPaperName")
  Debug.Print "Paper Orientation: "  & IIf(GetCExpressionValue("plotUI.uiOrientation") = 0, "Portrait", "Landscape")
  Debug.Print "Paper Size: "         & GetCExpressionValue("plotUI.uiFormSizeX") & ", " & GetCExpressionValue("plotUI.uiFormSizeY")
End Sub

Controlling Printing with VBA

The description that follows originated with MicroStation V8i. Now that MicroStation CONNECT provides print classes in VBA, you no longer need to control the PLOTDLG built-in application. We maintain that information if you're writing VBA code for MicroStation V8i. See this page about printing with VBA for MicroStation V8i.

Controlling Print Organizer with VBA

Q How can I setup Print Organizer programmatically?

A Print Organizer is a .NET AddIn for MicroStation, implemented in bentley.printorganizer.dll, which you will find in the \MicroStation\assemblies folder.

Here's a subroutine that queues commands to Print Organizer …

Sub PrintOrganizer()
    CadInputQueue.SendKeyin "mdl load bentley.printorganizer.dll"
    CadInputQueue.SendKeyin "PRINTORGANIZER NEW"
    Const PrintDriver                       As String = "pdf.pltcfg"
    CadInputQueue.SendKeyin "PRINTORGANIZER PRINTERDRIVER  " & PrintDriver
    CadInputQueue.SendKeyin "PRINTORGANIZER ADD FILE  c:\cadfiles\model1.dgn"
    CadInputQueue.SendKeyin "PRINTORGANIZER ADD FILE  c:\cadfiles\model2.dgn"
    CadInputQueue.SendKeyin "PRINTORGANIZER ADD FILE  c:\cadfiles\model3.dgn"
    Const PrintStyleName                    As String = "print-style"
    CadInputQueue.SendKeyin "PRINTORGANIZER APPLYPRINTSTYLE ALL " & PrintStyleName
    CadInputQueue.SendKeyin "PRINTORGANIZER SUBMITAS SINGLE"
    CadInputQueue.SendKeyin "PRINTORGANIZER PRINT ALL"
    CadInputQueue.SendKeyin "PRINTORGANIZER EXIT"
End Sub

In the above VBA code, I've declared a couple of constant Strings: PrintDriver and PrintStyleName. You need to subsitute the name of your chosen print driver file and print style name. I've also hard-wired the DGN file names, which you must replace with your own file names.

Setting a View with Print Organizer

There's no command to set a view with Print Organizer as there is with the Print Dialog. Instead, you specify a view in a Print Style. Here's a comment from Bentley Systems printing guru Andrew Edge from the Printing and Plotting Forum …

The key-in you're looking for is 'printorganizer applyprintstyle'. That can be used in conjunction with a print style you define in a dgnlib that sets the print definition properties according to your standards. That can include the view number.

Find Print Driver

Print driver files (also known as plot configuration files) are stored by default in MicroStation's \Workspace\System folder. They are XML files and have a .pltcfg extension.

If you customise one of the supplied plot configuration files you are encouraged to place it in the \Workspace\Standards folder. That folder is not modified when you install a MicroStation update, and so your customized plot configuration files will remain undisturbed.

MicroStation configuration variable MS_PLTCFG_PATH points at those folders.

The FindPrintDriver function searches the folders specified by MS_PLTCFG_PATH to find your print driver file passed in variable driverName. It returns True if the file is found, and copies the full path into your variable driverPath.

This function uses another helper, FindFile, which is described in this article.

' ---------------------------------------------------------------------
'   FindPrintDriver
' ---------------------------------------------------------------------
Private Function FindPrintDriver(ByRef driverPath As String, ByVal driverName As String) As Boolean
    FindPrintDriver = False
    Const CFGVAR_MS_PLTCFG_PATH             As String = "MS_PLTCFG_PATH"
    Dim inform                              As String
    If ActiveWorkspace.IsConfigurationVariableDefined(CFGVAR_MS_PLTCFG_PATH) Then
        If FindFile(driverPath, driverName, CFGVAR_MS_PLTCFG_PATH, vbNullString) Then
            FindPrintDriver = True
            inform = "Print driver " & SingleQuote(driverPath)
            ShowMessage inform, inform, msdMessageCenterPriorityInfo
            Debug.Print inform
        Else
            inform = "Print driver " & SingleQuote(driverName) & " not found in any path defined by " & SingleQuote(CFGVAR_MS_PLTCFG_PATH)
            ShowMessage inform, inform, msdMessageCenterPriorityError, True
            Debug.Print inform
        End If
    Else
        inform = "Configuration variable " & SingleQuote(CFGVAR_MS_PLTCFG_PATH) & " is not defined"
        ShowMessage inform, inform, msdMessageCenterPriorityError, True
        Debug.Print inform
    End If
End Function

Questions

Post questions about MicroStation programming to the MicroStation Programming Forum.