NI TestStand

Showing results for 
Search instead for 
Did you mean: 

How to specify environment when using custom OI

Go to solution

How do I specify which TestStand 2016 environment to use when running from a custom operator interface? I want to create multiple environments but I don't know how I can have my software ensure I am using the right environment.

0 Kudos
Message 1 of 16

You can specify an environment through the command line when you launch the operator interface (TS Help: Choosing an Environment). I like to make a shortcut that already has the /env specified, similar to how the full featured OIs specify the /editor or /operatorInterface flags.


From your OI code, you can call Engine.GetEnvironmentPath to check the current environment and react appropriately.
0 Kudos
Message 2 of 16

The question is, once I know the environment I'm in, can I programmatically change it or does it require the user to open the Sequence Editor?

0 Kudos
Message 3 of 16
Accepted by Skeptical

Changing environments requires exiting the existing application instance and launching a new one. You could programmatically re-launch your application with the correct environment, but there's no way around restarting it if you need to change environments.


The engine reads some config files on initialization, so it needs to be started with the environment you want to use.
Message 4 of 16

It would be nice if I could programmatically set the environment in the AxApplicationManager when it gets initialized or something like that. Perhaps a future version will allow that. Thanks for your response.

0 Kudos
Message 5 of 16

I would like to pass an environment to the Engine as well, especially when I am debugging my TSUI. Right now I have to add information to the Global environment in order to debug the OI. That is slow goin' and hard to explain. I see this as very similar to a Python virtualenv, where the shell can be activated to use said env. To follow that logic, I tried setting the "TestStand" environment variables of a cmd.exe instance to my AppData and PubDocs folders. When I ran seqedit.exe from that cmd.exe I was hoping the engine would use those environment variables and launch in a fake Global environment that I had overridden.

That didn't work Smiley Sad I guess seqedit has hardcoded Global environment settings?

I don't see why the Application Manager's GetEngine() method couldn't include an override for providing an environment file.

Another option would be to allow the setting of the Application Managers' CommandLineArgs. I tried to use the .Add() method on that but it errors and says you cannot set these strings.

I agree that we need to be able to, somehow, pass environments in programmatically.

0 Kudos
Message 6 of 16

Since the Environment is needed to initialize the engine, it needs to be set before creating one. This is possible with a customOI similar to what is described here:


For the sequence editor, you're limited to command line args.
0 Kudos
Message 7 of 16

Good to know. I use a custom OI to execute the sequences but typically edit them in the sequence editor.

0 Kudos
Message 8 of 16

If this to say that the ApplicationManager that I use to call GetEngine() has already loaded the engine and, therefore, config files?

I understand the complexity if that is the case.

0 Kudos
Message 9 of 16

That's right
0 Kudos
Message 10 of 16