Example Code

Using the TestStand API to create a Data Type

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.


  • Teststand

Code and Documents




 This example demonstrates how you can use the TestStand API to:

  • Create a new data type.
  • Add fields to the type.
  • Add the data type to the type usage list of a sequence file.
  • Configure struct and cluster passing settings.
  • Create an instance of the data type in a sequence file.


If you are not familiar with TestStand data types, refer to NI TestStand Type Management Best Practices for more information before using this example.


This example uses the TestStand API to create a new data type, and create an instance of the type in a sequence file:


  1. Obtain a reference to the sequence file which will contain the type.

    Locals.SequenceFile = RunState.Engine.GetSequenceFileEx("", 107, ConflictHandler_UseGlobalType)
  2. Check if the desired type name is already loaded in memory before attempting to create the type.  If the type does not exist, the output is NULL.

    Locals.Type = RunState.Engine.GetTypeDefinition(Parameters.TypeName)
  3. If the type does not exist (Locals.type in NULL), create it, and add it to the sequence file's type usage list (the list of types stored with the sequence file).

    Locals.Type = RunState.Engine.NewDataType(PropValType_Container, False,"", 0)
    Locals.SequenceFile.AsPropertyObjectFile.TypeUsageList.InsertType(Locals.Type, 0, TypeCategory_CustomDataTypes)
  4. Set the name of the data type, and add fields to the data type using the PropertyObject API.

    Locals.Type.AsPropertyObject.Name = Parameters.TypeName,
    Locals.Type.AsPropertyObject.SetValNumber("NumericField", PropOption_InsertIfMissing, 0),
    Locals.Type.AsPropertyObject.SetValString("StringField", PropOption_InsertIfMissing, "")
  5. Enable Cluster and Struct passing, which allows passing instances of the type to LabVIEW and DLL code modules.

    RunState.Engine.GetAdapterByKeyName(FlexCAdapterKeyName).AsCommonCAdapter.SetAllowStructPassing(Locals.Type, True),
    RunState.Engine.GetAdapterByKeyName(FlexLVAdapterKeyName).AsLabVIEWAdapter.SetClusterPassingEnabled(Locals.Type, True)
  6. Create a new instance of the data type in the MainSequence Locals.

    Locals.SequenceFile.AsSequenceFile.GetSequenceByName("MainSequence").Locals.NewSubProperty("instance", PropValType_NamedType, False, Parameters.TypeName, 0)
  7. Increment the change count to indicate that the sequence file has been modified.

  8. Save the sequence file and release the reference.

    RunState.Engine.ReleaseSequenceFileEx(Locals.SequenceFile, 0)


Hardware and Software Requirements

Create Data Type Using TestStand API.zip

TestStand 2019 or Compatible 


Steps to Implement or Execute Code

  1. Extract the attached archive, and open Create Data Type Using TestStand API.seq.
  2. Run the sequence using Execute » Run Mainsequence.
  3. When prompted, select the TargetSequenceFile.seq.
  4. After the execution completes, open TargetSequenceFile.seq in the sequence editor.  Press Ctrl + T to open the types pane.  Observe that a new type is present under Custom Data Types in the sequence file.


  5. select the TargetSequenceFile.seq tab.  Observe that an instance of the type is generated in the MainSequence local variables.


Additional Information or References

  NI TestStand Type Management Best Practices 

Al B.
Staff Software Engineer - TestStand

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