Introduction

This article is written for an audience of Visual Basic for Applications (VBA) programmers. Specifically, VBA programmers wanting to write code for Bentley Systems MicroStation® VBA. Questions similar to this appear on the Bentley Discussion Groups.

MicroStation uses the function keys on your computer's keyboard. Function keys are arranged along the top of your keyboard. They usually have labels F1, F2, etc. You can read more about MicroStation and function keys in the MicroStation help document that is installed with MicroStation: A function key menu is a file that contains keyboard function key definitions — assignments of actions to function keys. Function key definitions contain action strings that cause an action to occur when you press the function keys.

MicroStation lets you assign your own menu to the function keys. A function key menu is a set of MicroStation commands that you want to assign to each function key. You can have many menus, but only one menu can be active at any one time.

Q How do I load a MicroStation function key menu?

Q How do I load a MicroStation function key menu using VBA?

A MicroStation provides a set of function key assignments in its default function key menu. Those are documented in MicroStation help. You can reassign function keys individually, or en bloc using a function key menu file.

To see the current function key assignments, open the Function Keys dialog. You can open the Function Keys dialog either from the Workspace|Function Keys menu, or by using the keyin DIALOG FUNCKEYS. Here's the Function Keys Dialog showing MicroStation's default function key assignments …

Function Keys Dialog

Function Key File

A set of function key assignments is stored in a function key menu file. The default function key menu is named funckey.mnu. It is located in the folder specified by configuration variable _USTN_USERINTROOT in sub-folder Fkeys. In a standard installation, this will be  …\Workspace\interfaces\Fkeys. The configuration variable that specifies the complete path to the function key menu is MS_FKEYMNU. In other words, in a standard MicroStation installation the function key menu is defined like this …

MS_FKEYMNU = $(_USTN_USERINTROOT)Fkeys\funckey.mnu 

You can create multiple function key menu files. Only one file at a time may be active. You can load a file in one of several ways …

For example, if you have developed your own set of function key assignments and stored them in menu MyFuncKeys.mnu, then you could assign them to MicroStation's function keys by defining MS_FKEYMNU like this …

MS_FKEYMNU = $(_USTN_USERINTROOT)Fkeys\MyFuncKeys.mnu 

The keyin to attach a function key menu is …

ATTACH MENU <Path to FKeys Folder>MyFuncKeys.mnu,FK 

or

AM=<Path to FKeys Folder>MyFuncKeys.mnu,FK 

Load a Function Key menu using VBA

If you've read the background to function keys, function key menus, and configuration variable then the solution to the question "How do I load a function key menu using VBA?" is almost self-evident …

  1. Get the value of _USTN_USERINTROOT
  2. Build the path to your function key menu
  3. Queue the keyin to load your menu

Here's a first shot at the VBA to implement that …

Sub AttachFunctionKeyMenu ()
    Const Path As String _
       ="C:\Program Files\Bentley\Workspace\interfaces\fkeys\"
    CadInputQueue.SendCommand "ATTACH MENU " & Path & "FunckeyRJB.mnu,FK"
End Sub

A disadvantage to that implementation is the hard-coded folder path. If you were to move your function key menus to a different location — you might have a mult-user networked CAD installation, for example, where the menus are on a network folder — then you would have to re-code the macro. Fortunately, because the path is partially found in a configuration variable, you can make the VBA more versatile like this …

Sub AttachFunctionKeyMenu ()
    Dim cfgVar As String
    cfgVar = ActiveWorkspace.ConfigurationVariableValue ("_USTN_USERINTROOT")
    Dim path As String
    path = cfgVar & "fkeys\"
    CadInputQueue.SendCommand "ATTACH MENU " & path & "FunckeyRJB.mnu,FK"
End Sub

Load a Function Key Menu when MicroStation Starts

Note that the VBA macro, as with the MicroStation keyin, does not have a permanent effect. The next time MicroStation loads, it uses the function menu that MS_FKEYMNU specifies. In other words, if you want a particular function key menu to be used each time you start MicroStation, then add a definition for MS_FKEYMNU to one of your configuration files.