NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Install Custom Types Using API

Solved!
Go to solution

Hello,

 

In TestStand 2021, if you want to "install" a custom types file (let's call it INSTALL_MyTypes.ini), you can drop it in the %Users%\Documents\National Instruments\TestStand 2021 (32-bit)\Components\TypePalettes folder.  Then when you open TestStand the types magically appear in the Types window.

 

We have a .NET project with an installer that uses a Custom Action to backup any existing version and then copy that file to the correct directory.  So, to be clear, the installer installs the file in the application folder, checks for any existing and backs it up, then copies the file from the application folder to the TypePalettes folder.  This may be ugly, but it works.

 

My question is this:  Is there a way to write some C# code (using the NI assemblies) that can install these types?  Are there API methods that can accomplish this, or is the way we're doing it the preferred and recommended method?

 

Thanks!

0 Kudos
Message 1 of 2
(827 Views)
Solution
Accepted by topic author ScottTE

After a little digging, I finally found the solution:

 

using NI_AX = NationalInstruments.TestStand.Interop.UI.Ax;
using NI_API = NationalInstruments.TestStand.Interop.API;
...

NI_AX.AxApplicationMgr appMgr; // initialized elsewhere.
string typeFilePath = <pathToIniFile>;

// First, fetch the existing types from the TS engine.  If you don't do this, when you install 
//  the new one, you will lose all the existing ones.
List<NI_API.PropertyObjectFile> files = appMgr.GetEngine().GetTypePaletteFileList().ToList();

// Second, create a new type object to add to the collection:
NI_API.PropertyObjectFile newFile = appMgr.GetEngine().NewPropertyObjectFile(NI_API.PropertyObjectFileTypes.FileType_TypePaletteFile);
newFile.Path = typeFilePath;

// Add it.
files.Add(newFile);

// Finally, add the complete list back to the TS engine and make sure to load it.
appMgr.GetEngine().SetTypePaletteFileList(files.ToArray());
appMgr.GetEngine().LoadTypePaletteFilesEx(
  NI_API.TypeConflictHandlerTypes.ConflictHandler_UseGlobalType,
  PropertyOptions.PropOption_NoOptions);

 

Hope this helps whomever stumbles across it in the future.

0 Kudos
Message 2 of 2
(797 Views)