Example Code

Using the TestStand API to Add Items to the Templates List

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • Teststand

Code and Documents

Attachment

Overview

This example shows how to programmatically create new Step, Variable, and Sequence templates in the sequence editor using the TestStand API.

 

Description

In order to create new templates, this example completes the following steps:

 

  1. Access the Templates file using the Engine.

    Locals.templatesFile= RunState.Engine.GetTemplatesFile(0)
  2. Use the PropertyObjectFile method to access the data within the templates file, and add the new template items as subproperties.  Use the clone method to create a new instance of the new item to be used as a template.

    Locals.templatesFile.AsPropertyObjectFile.Data.Root["Steps"].SetPropertyObjectByOffset(0,1,RunState.SequenceFile.GetSequenceByName("Template").GetStepByName("Test Step", StepGroup_Main).AsPropertyObject.Clone("", 0))
  3. Increment the change count of the file.

    Locals.templatesFile.AsPropertyObjectFile.IncChangeCount(),
  4. Refresh the window to update the templates pane.

    RunState.Thread.PostUIMessageEx(UIMsg_RefreshWindows,0,"",Nothing,True)

 

Hardware and Software Requirements

Dynamic Template Insertion - TS2012.seq

TestStand 2012 or Compatible

Dynamic Template Insertion - TS2016.seq

TestStand 2016 or Compatible

 

Steps to Implement or Execute Code

  1. Open the attached sequence file, and execute it using Execute » Run MainSequence. 
  2. Once the sequence runs, observe that the templates have been updated in the sequence editor.

    Capture1111.PNG

 

 
Manooch H.
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.