Obtaining References to Objects in a Known Target VI Using VI Scripting

Requires: VI Scripting

When you create a new VI from a template, you usually want to make small modifications to the code that LabVIEW copied from the template into the new VI. To make these modifications, you must obtain references to the objects in the new VI that you want to inspect or modify. After you obtain these object references, you can wire them to Property Nodes or Invoke Nodes to get or set information about the referenced objects. The easiest way to obtain references to objects in the new VI is to use the Open VI Object Reference function. However, to use this function, the desired objects in the new VI must have unique labels. If the desired objects do not have unique labels, you must use a different, more complex procedure to obtain references for these unlabeled or unknown objects.

What to Use

This VI Scripting task requires the following objects:

Open VI Object Reference Class Specifier Constant Close Reference
 Add  Find
 Add  Find
 Add  Find

What to Do

Before you start: Open the Obtaining Known Object Reference VI in the labview\examples\Application Control\VI Scripting\Finding and Modifying Objects directory for an example that illustrates each step of the following procedure.

 Open Example

Expand the procedure for more information about this specific example.

  1. Obtain a reference to the target VI that contains the object with which you want to interact.
  2. Determine the identifying information of the object whose reference you want to obtain.

    1. Class type—Every front panel or block diagram object that you can use with VI Scripting is a member of a VI Server class, so the reference for a given object is of a corresponding class. Refer to the anatomies of VIs to determine the class name of the object you want to access. Use the Class Specifier Constant to indicate the class of object for the Open VI Object Reference function.

      Example Details

      In the example, the Edit Me control is a member of the Numeric class.

    2. Owner—Every object on both the front panel and the block diagram has an owner. In the simplest case, the owner of an object is either the front panel or the block diagram of a VI. However, if an object resides within a substructure such as a loop, a Case structure, a sequence structure, or a cluster, that substructure owns the object.

      Example Details

      In the example, the Edit Me control resides on the front panel of the target VI, so the front panel of the target VI owns the control. Thus, the scripting VI uses the VI:Front Panel property to obtain the reference to the front panel of the target VI.

      Note The Control and ControlTerminal classes are often confused. A ControlTerminal object is the block diagram representation for the corresponding front panel Control object. Thus, the front panel of the target VI owns the Edit Me Control object, and the block diagram of the target VI owns the associated Edit Me ControlTerminal object. You can change the numeric representation of a Control object but not of a ControlTerminal object.
    3. Label—This is the name assigned to the desired object in the target VI.

      Example Details

      In the example, the label of the control to change is Edit Me.

  3. Use an Open VI Object Reference function to obtain a reference to the desired object by wiring the identifying information from step 2 to the function.
  4. Get or set information about the referenced object by wiring the object refnum output of the Open VI Object Reference function to a Property Node or an Invoke Node.

    Example Details

    In the example, the scripting VI uses the Numeric:Representation property to set the numeric representation of the Edit Me control.

  5. Use the Close Reference function to close each open object reference when you are finished using it.

Caveats and Recommendations

Additional Examples

Refer to the Creating New VI From Template VI in the labview\examples\Application Control\VI Scripting\Creating VIs directory for an example of obtaining references in a known VI.

 Open example  Find related examples