NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Creating and changing step variables

Solved!
Go to solution

This is a two-part question, both pertaining to step variables:

 

1) Is there a way to programmatically (C#) create a new step variable when dragging and dropping a custom step into the steps window?  I created the step type, set up the OnNewStep substep (which calls a form in a C# code module) and am able to set Locals and FileGlobals, but not Steps.  I did notice that the steps don't seem to appear in the Steps window until after the form closes, so is it even possible to create it at that point?

I am looking to do something like this:

 

SequenceContext.Step.CreateValString("MyStepVariable", "SomeValue);

 

 

2) How would I edit an existing step variable.  Let's say I already have the variable created (some other way).  Is there a way to change its value in code?  I see the SequenceContext.Locals and SequenceContext.FileGlobals.  However, I am unable to find anything that would work like this:

 

 

SequenceContext.Step.SetValString("MyStepVariable", "Hello");

FYI, neither of these are meant to run when the step actually runs.  They would be called when adding or editing a step.

 

Thanks a ton in advance for any and all suggestions.

0 Kudos
Message 1 of 4
(3,824 Views)

If you can pass the step object in as a parameter (property object) then you should be able to do what you need.  I just tested it.

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
0 Kudos
Message 2 of 4
(3,802 Views)
Solution
Accepted by topic author ScottTE

So I just tested with SequenceContext going into my OnNewStep substep.  I only know LabVIEW (sorry) so I was doing it in LV.

 

Basically I used the Get TestStand Property to get a Property Object.  My lookup string was "Step" (relative to Sequence Context).  Then I typecast the Proprty Object to Step type using the TS API. (in LabVIEW we use variant to data, not sure about C#),  After that I just use the SetValString("New String Name", 0x1, "Value").  You need the 1 to create the variable.

 

Hope this helps,

jigg
CTA, CLA
testeract.com
~Will work for kudos and/or BBQ~
Message 3 of 4
(3,799 Views)
Solution
Accepted by topic author ScottTE

Yup, calling the AsPropertyObject() method seemed to do the trick:

 

mySequenceContext.Step.AsPropertyObject().SetValString("MyStepVariable", 0) = "Whatever";

Thanks for your help!

 

0 Kudos
Message 4 of 4
(3,784 Views)