How to do Menu Launch VIs
Customizing LabVIEW Menus
LabVIEW provides a mechanism, which allows the user to open VIs and help files by selecting them from the Tools and Help pull-down menus. This is a very powerful feature for development tools creation, so I will describe how this works. When LabVIEW starts up it does several things, which include initializing the menus. This is a process where LabVIEW looks for files within specific directories for inclusion in the menus.
Menu Launch Folders
- .\wizard - File menu-launch
- .\project - Tools menu-launch
- .\help - Help menu-launch
The .\wizard, .\project, and .\help folders are intrinsically related to the "File", "Tools", and "Help" menus, respectively. When you install a LabVIEW add-on, you will notice that new menu items are usually added to these two menus. This was achieved by adding files to the .\project and .\help folders. Through a little experimentation the nature of this process has been determined to be the following:
Technical details
First, LabVIEW looks in the .\wizard, .\project, and .\help folders for standalone VIs and top-level VIs within LLBs. In the .\help folder, it also looks for .hlp and .chm compiled help files. These files are then opened when selected from the menu. LabVIEW will look recursively through all subfolders and LLBs looking for these files of interest. However, the search will ignore any VIs, folders, or LLBs whose name begins with an underscore ("_") character. When the search finds a file of interest it will create a menu item at a location, which reflects where it found it in the directory structure inside the project or help folder. For Example, if it finds the file .\project\Goop Tools\Rename Goop Class.vi, it will create the menu item Tools/GOOP Tools/Rename GOOP Class.
Menu Naming method
Here is where a twist is thrown into the naming rules. You can override the names of the VIs, .chm and .hlp files, folders and LLBs so that they are named differently in the menu structure from their names on disk. For VIs, LabVIEW will use the "Window Title" as the menu name (this is also the VI Server VI:Front Panel Window:Title property). But, by placing a text file with the identical root name (RootName.vi, RootName.txt) in the same location as the folder or file, you can specify the name LabVIEW should use in the menus. The name you wish to use in the menu should be placed in the text file. For example, if you have a VI called MyBuggyCode.vi, you can make the menu item show up as Elegant Solution by creating a text file called MyBuggyCode.txt that contains the contents "Elegant Solution" and placing it in the same directory as MyBuggyCode.vi.
Text File Guidelines:
- The text file must have the same name as its containing folder.
- Folders and VIs should be listed by filename in the desired order in the text file.
- Separators can be denoted by a dash (“-”).
- Each entry - whether a VI, folder, or separator – must occupy its own line in the text file.
Note that this override method works for LLBs, folders, .hlp, and .chm files, but for .hlp and .chm files you must also add the characters ".hlp" or ".chm" after the menu item name in the overriding text file. The file MyCHM.chm should have an override text file called MyCHM.txt that contains the contents "All The Help You Need.chm" This will cause its menu name to be "All The Help You Need". Any items that are not listed in the text file will be added after the text file's contents.
Example
The following image is an example of a custom menu item, “Custom Menu” created in LabVIEW. Notice that “Custom Menu” contains two items and one sub-menu. The folder structure is also shown. Notice that this folder is located in labview\project and contains two VIs and one sub-folder. The VIs are displayed in the menu as items, and the sub-folder is displayed as a sub-menu.


Autorun
How does the developer use this feature, whereby they can open VIs and help files from the menu? VIs placed in the Tools menu (.\project folder) should always be set to "Run When Opened". This will cause them to look and feel like a functional dialog or tool once they are opened after being selected from the menu.
Notes
The .\wizard (Files) VIs don't show up in Project windows.
Get calling VI
It many situations, it is useful for a menu item to obtain information about the VI that was open when the menu was selected. Menu Launch VI Information.vi (available since LabVIEW 2009) returns the Application reference and VI Name for the VI which was active when this menu item was launched. It is available in labview\vi.lib\VIServer
