Before you start: Open the Adding Objects VI in the labview\examples\Application Control\VI Scripting\Creating 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.
Determine the defining information of the new object that you want to create.
Owner reference—Every object on the front panel or 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. The Additional Examples section contains examples of adding an object to a loop, an array, and a cluster.
Example Details
In the example, the goal is to create the new Subtract function on the block diagram of the target VI. The scripting VI uses the reference to the target VI as the owner for the new Subtract function even though the block diagram of the target VI is the more precise owner. However, the New VI Object function recognizes when an object such as a Subtract function can appear only on a block diagram and places the new object accordingly.
Class name—Every front panel or block diagram object that you can create with VI Scripting is a member of a VI Server class. Refer to the anatomies of VIs to determine the class name of the object you want to create. Use a class specifier constant to indicate the class of object for the New VI Object function.
Example Details
In the example, the Subtract function is a member of the Function class.
Style—Every native LabVIEW object has a style that further defines exactly what kind of object it is. You can use the Control:Style ID property or the Node:Style property to help identify the style of an object that you want to create.
Note You do not need to specify a style if you are adding a subVI or a user-defined control to the target VI.
Example Details
In the example, the scripting VI is creating a Subtract function, so the style is Subtract. Notice that the style of a node is often different than the class of the node.
Location—You must specify the location of any object that you create. This location is relative to the origin of the owner of the object.
Example Details
In the example, the scripting VI specifies a location of (100, 200) for the Subtract function.
(Optional) Path to subVI or user-defined custom controls—SubVIs and user-defined custom controls require you to wire a path to the source file to the path input of the New VI Object function. Refer to the Additional Examples section for an example of creating a call to a subVI.
(Optional) Size of new object—You can specify a size for any object that you can manually resize.
Example Details
In the example, the scripting VI is creating a Subtract function, which is not resizeable.
Use a New VI Object function to add the new object to the target VI by wiring the information from step 2 to the function.
Refer to the Additional Examples section for an example of using VI scripting to wire objects.
Use the Close Reference function to close each open object reference when you are finished using it.
Caveats and Recommendations
Create complicated new VIs from a template when possible—Although you can create a new VI programmatically by creating each component object one at a time, it is much easier to create a new VI from a template and then modify small sections of the code. The Creating New VI From Scratch VI in the Additional Examples section demonstrates that creating even a simple target VI one object at a time requires extensive scripting code. You can avoid such complicated scripting code by creating a new VI from a template.
Create complex controls from a template when possible—Although you can programmatically create a complex control one element at a time, it is easier to create a custom control manually, add an instance of the control by following the previous procedure, and then modify individual parts of the control as necessary. If you have a reference to a custom control, you also can use the VI:Create from Reference method to create a copy of the control.
Close all references that you open—An excessive number of open references negatively impacts the performance of a VI. Read about closing VI and VI object references for more performance details.
Additional Examples
Refer to the Creating New VI From Scratch VI in the labview\examples\Application Control\VI Scripting\Creating VIs directory for an example of adding an array control, a numeric indicator, and a call to a subVI to a target VI.
Open example Find related examples
Refer to the Drop Add Function Inside While Loop VI in the labview\examples\Application Control\VI Scripting\Creating Objects directory for an example of adding an Add function inside of another object such as a While Loop.
Open example Find related examples
Refer to the Drop Digital Numeric Inside Cluster VI in the labview\examples\Application Control\VI Scripting\Creating Objects directory for an example of adding an object to a cluster.