Programmatically Retrieve a List of TestStand Variable Names

Updated Apr 3, 2023

Environment

Software

  • TestStand

I want to programmatically get a list with the names of my TestStand variables (i.e. Locals, Parameters, FileGlobals, StationGlobals) from my code module. How can I do this?

You can use two TestStand API methods defined in the PropertyObject class:
  1. PropertyObject.GetNumSubProperties(lookupString) This method returns the number of subproperties belonging to a particular object (e.g. number of local variables, sequence file globals, subproperties of a TestStand container and so on). You can then have a loop with as many iterations as number of subproperties to get the name of each variable using the PropertyObject method described next
  2. PropertyObject.GetNthSubPropertyName(lookupString, index, options)  - This method returns the name of a subproperty that the index specifies.
How to correctly use these methods and pass them the correct reference depends on how your code module is called:
  • If the code module is called from a step in a sequence you need to pass the SequenceContext to your code module and use it as the ActiveX reference for the PropertyObject methods described above. Please refer to the following instructions, based on your development environment:
    • ​In LabVIEW, you must first call the SequenceContext.AsPropertyObject  method and use the return value as the ActiveX reference for the PropertyObject methods. Pass one of the following values to the lookupString parameter: LocalsParametersFileGlobals or StationGlobals, depending on the scope of the variables you want to obtain. Do not use the quotes in LabVIEW.
    • In LabWindows/CVI your code might look like:
// Get the number of Local Variables 
tsErrChk (TS_PropertyGetNumSubProperties (testData->seqContextCVI, &errorInfo, "Locals", &NumOfSubproperties));

for (Index == 0; Index < NumOfSubproperties; Index++)

// Get the Nth variable name and store it in the variable called "VariableName" 
tsErrChk (TS_PropertyGetNthSubPropertyName (testData->seqContextCVI, &errorInfo, "Locals", Index, 0, &VariableName));
}
  • In .NET your code may look like:
// Gets a list of Local Variables 
PropertyObject locals = mySequence.Locals;
 
Once you have the desired object (i.e. Locals, Parameters, FileGlobals or StationGlobals object), use it as the ActiveX reference for the PropertyObject methods described above and use an empty string for the lookupString parameter.