Company Events Academic Community Support Solutions Products & Services Contact NI MyNI

Programmatically Scripting VIs in LabVIEW

LabVIEW 2013 Help

Edition Date: June 2013

Part Number: 371361K-01

»View Product Info

You can use the VI Scripting VI and functions with the associated properties and methods to create, edit, and run VIs programmatically. With VI Scripting, you can reduce the amount of time you spend on repetitive VI editing tasks, such as:

  • Creating several similar VIs
  • Aligning and distributing controls and indicators
  • Displaying or hiding control and indicator labels
  • Wiring block diagram objects
Note  You must enable VI Scripting to use the VI Scripting VI and functions.

Prior to completing tasks using VI Scripting, consider reviewing the following resources:

  • Programmatically Controlling VIs—Scripting VIs involves obtaining references to objects, invoking methods, and getting and setting properties. The Programmatically Controlling VIs book in the LabVIEW Help provides information about working with the VI Server and reference numbers, as well as information regarding VI Scripting.
  • LabVIEW Examples—You can complete numerous tasks using VI Scripting, depending on your need. The VI Scripting examples installed with LabVIEW provide specific examples for common VI Scripting tasks. These examples are useful resources for learning about the power of VI Scripting.

  • NI Developer Zone—The NI Developer Zone provides additional tutorials as well as user discussions about VI Scripting.

Benefits of VI Scripting

You can use VI Scripting to complete simple and complex tasks ranging from displaying or hiding control labels to creating entire VIs programmatically. For example, if you decide to display block diagram labels during development, rather than selecting each block diagram object, right-clicking, and selecting Visible Item»Label from the shortcut menu throughout the application, you can automate the process by writing a VI that utilizes VI Scripting to programmatically complete the task.

The following block diagram shows an example of a VI Scripting application that displays the labels of block diagram objects on a specified VI.

A more complex example of a VI Scripting task is creating entire VIs programmatically. Typically, you create a VI using a process similar to the following steps.

  1. Select File»New VI.
  2. Build a user interface by selecting front panel controls and indicators from the Controls palette and adding them to the front panel. You also must arrange the front panel objects to create a user interface with which the user can interact easily.
  3. Control the user interface by selecting structures, functions, and so on from the Functions palette and adding them to the block diagram. You also must wire the block diagram terminals to the appropriate nodes and ensure a readable diagram.
  4. Finally, if the VI will be used as a subVI, you assign front panel controls and indicators to the terminals of the connector pane.

If you need to create multiple VIs that differ slightly, rather than using the previous manual process to create each one, you can create a VI Scripting application to programmatically create the new VIs, each with the modifications you need.

Building VI Scripting Applications

After you enable VI Scripting, you can use the VI and functions on the VI Scripting palette in conjunction with the functions and nodes on the Application Control palette to create VI Scripting applications.

Note  The VI Scripting VI, functions, properties, and methods appear blue on the block diagram as shown in the following image.

For each VI Scripting application, you must obtain a reference to the object, or objects, you want to create or modify. The most common way to obtain a reference to an object is to begin by obtaining a reference to the VI that contains the object you want to modify. You can create a new VI and obtain a reference to the VI using the New VI function, or you can obtain a reference to an existing VI using the Open VI Reference function. After you obtain the VI reference, you can use the VI and functions on the VI Scripting palette in conjunction with the functions and nodes on the Application Control palette to obtain references to VI objects.

When you interact with complex VI objects, you must obtain references to specific elements of those objects. For example, to create a new wire that enters a For Loop, you must obtain references to the loop itself, a new loop tunnel, and the inner and outer terminals of the loop tunnel. Refer to the Anatomy of a VI and Common VI Objects topic to identify specific elements of an object you want to create or edit with VI Scripting. If you obtain references to VI objects that are contained within another VI object, be sure to retain the reference to the container object until all references inside the object are closed.

The following image demonstrates one possible way to obtain a VI reference and then obtain references to block diagram objects in the referenced VI.

You can identify objects in a VI by their class name, data type, label, tag, or array index. The following functions and nodes are common ways to identify objects and obtain object references to use in a VI Scripting application:

Note  Block diagram objects do not display a label by default. To use the Open VI Object Reference function to obtain a reference to an object, you must display the label first. If you intend to use object labels to obtain references, create distinct and identifiable labels to help you locate the correct object.
  • Control and Terminal properties
  • Traverse for GObjects VI
  • SetTag and GetTag methods
  • Firing Order property
  • All Objects[] property
    Note  The All Objects[] property does not search container objects recursively. To search all objects in a VI, use the All Objects[] property on each container object including the front panel, the block diagram, structures, and arrays.

Some common tasks you might complete in a VI Scripting application include the following:

Refer to the examples in the labview\examples\VIScripting folder for examples that demonstrate these tasks.


Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit