Shortcut Menu Plug-in for LabVIEW IDE

Table of Contents

Overview

LabVIEW 2015 introduced the ability to add custom elements to context menus (the right-click menus) of front-panel and block-diagram objects. This allows you to customize your LabVIEW editor, using G code, to add new menu items, reorganize or replace existing menu items, and manipulate menu items (enable/disable, check/uncheck, ...).

LabVIEW context menus can be accessed from the front-panels and block-diagrams when editing and only from block-diagrams at run time. At runtime, the context menu of the front-panels uses another technology, known as Run-Time Menu, *.rtm files.

How does it work?

At startup, LabVIEW searches for and loads context menu plug-ins from LLB in specific locations.

There are 2 types of plug-ins located in different locations:

If two plug-ins have the same name, LabVIEW will prioritize the plug-in in the <LabVIEW installation directory>\resource\plugins\PopupMenus and will not run the other.

By default, the location of the <LabVIEW installation directory> is:

By default, the location of the <LabVIEW Data> directory is:

The Anatomy of a LabVIEW Shortcut Plug-in

A context menu plug-in must contain 3 main components:

A context menu plug-in must be saved in an LLB in order to be loaded by LabVIEW at launch. LLBs allow fast loading of the VI hierarchy and easy distribution with a single file. You can place other useful VIs in the LLB or in a subdirectory (they will be ignored by LabVIEW when searching for plug-ins).

Create your own context menu plug-in

How do I get started?

When you create a context menu plugin, you will go through 3 steps:

LabVIEW offers a utility to guide us in creating new context menu plug-ins.

Open the VI Create Shortcut Menu Plug-In From Template, located in the <LabVIEW installation directory>\resource\plugins\PopupMenus\ folder, and fill in the various fields and start running the VI.

You must enter the name of your plug-in, specify whether the context menu plug-in assigns context menus to edit or run, and optionally check/uncheck Open plug-in VIs after creation, before running the VI.

This utility generates the LLB, with the 3 main componentsof a Shortcut Menu plug-in, correctly named and in the right location.

Let's use a real-life example to illustrate the process of creating a context menu plug-in in LabVIEW. Let's say we want to implement a context menu plugin, called myPlugIn, that will change the background color of numeric controls and numeric constants.

Affected Items

First of all, we need to specify the objects of the front-panel or block-diagram on which our plug-in will work by modifying the type definition AffectedItems.

Affected Item

This Typedef, containing a cluster of VI Server Refnums arrays, represents the selected objects of the specific types.

You can add an object by adding an array of a refnum type, delete an object by deleting an array, or choose a different object by right clicking an array >> "Select a VI Server Class" and selecting the desired refnum type under the Generic Hierarchy.

To meet our myPlugIn requirements, the affected elements must have 2 arrays, one for digital control objects and one for digital constant objects. Then we have the following Typedef:

Affected Items myPlugIn

Depending on the object types defined in the Assigned Items Typedef, LabVIEW runs a specific set of VIs on a given right-click. In our case, our VI Builder will be called as a result of a right click on the digital controls of the front-panel and on the numerical constants of the block-diagram.



Remark

Builder VI

Now we need to tell LabVIEW which items to add, toggle, or remove from the context menu.

Builder VI

In the Builder VI, each menu item is described by:

With the entries of the VI we retrieve information about the selection of the user:

Based on the information in the user selection, it is possible to implement certain logics to tell LabVIEW which entries to add to the menu.

Back to our example, here are the rules we will follow:



cry Warning

 



Remark

VI Execute

Let's move on to the final step and define the actions that LabVIEW will perform when the user selects a custom item from the pop-up menu.

Execute VI

As noted above, LabVIEW loads context menu plug-ins at startup, so it is necessary to restart LabVIEW for the changes to take effect and for your plug-in to appear in the context menu.



cry Warning

 



Remark