Tutorial: Adding an Object to a VI Using VI Scripting

You can add objects to the front panel and block diagram of VIs using VI Scripting. This tutorial adds an object to the block diagram. Complete the following steps to add an object to a VI using VI Scripting.

Note Note  
  • This topic assumes familiarity with the VI Scripting introduction.
  • You must enable VI Scripting to display the VI Scripting VI and functions and use the associated properties and methods.
  1. Complete the previous exercise if you have not already completed it. If the untitled VI you created in the previous exercise is still open, close the VI.
  2. Remove the wires from the Close Reference function and move the function to the right to make room on the block diagram.
  3. Add the Block Diagram Window: Origin property to the Property Node and create a constant with Horizontal and Vertical input values of 0.

    This configuration sets the horizontal and vertical coordinates in the upper left-hand corner of the block diagram. Later in the exercise, you set the location of a For Loop so it also appears in the upper left-hand corner.
  4. Add the New VI Object function to the right of the Property Node.

     Add  Find
  5. Wire the reference out output of the Property Node to the owner refnum input of the New VI Object function.
  6. Right-click the vi object class input of the New VI Object function and select Create»Constant from the shortcut menu to create a class specifier constant.
  7. Click the class specifier constant and select Generic»GObject»Node»Structure»Loop»ForLoop from the shortcut menu.
    Note Note  In this exercise, you add a For Loop to the block diagram. However, with knowledge of the appropriate references, you can add and manipulate any front panel or block diagram object.
  8. Right-click the style input of the New VI Object function, select Create»Constant from the shortcut menu, and select For Loop from the pull-down menu of the constant.
  9. Right-click the location input of the New VI Object function, select Create»Constant from the shortcut menu, and enter 0 as the value for the Horizontal and Vertical inputs.

    This step specifies the coordinates of the location on the block diagram where you want the new object to appear.
  10. Right-click the bounds input of the New VI Object function, select Create»Constant from the shortcut menu, and enter 200 and 100 for the Width and Height inputs, respectively.

    This step specifies the size of the For Loop.
  11. Add another Close Reference function to the right of the existing Close Reference function. Closing both the reference to the VI and the reference to the For Loop ensures no memory leaks. Because the VI is the containing object of the For Loop, make sure to close the reference to the VI after you close the reference to the For Loop.

     Add  Find
  12. Complete all wiring to match the following block diagram.

  13. Save the VI.
  14. Run the VI.

LabVIEW creates and opens untitled front panel and block diagram windows. The block diagram contains a For Loop in the upper left-hand corner.

Additional Options for Creating Object References

Consider the following additional options to create references to objects:

To continue this tutorial, continue to the Tutorial: Repositioning an Object in a VI Using VI Scripting topic.