NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

How to copy dynamically a step from process model into a sequence?

The copied step should be save into the sequence.
0 Kudos
Message 1 of 2
(3,118 Views)
Eric,

Some of the details depend on where and when you are copy the step from and to. You could be copying between sequences that are not currently open and running. Or, one or both sequences could be running.

If it is the latter case then you will have an added complexity. Whenever, a sequences is executed its really a copy of sequence that is executed. Therefore, updating the execution copy does not update the sequence on disk and vice versa, updating the sequence on disk does not change the run-time copy.

The general flow is to:
-get a reference to the source step to be copied,
-clone it,
-insert the clone into the target sequence,
-save the target sequence file.

Getting a reference to the source step:
If you are copying the step from your running sequence then you can access the step property from the sequence context. For example,
-RunState.SequenceFile.Data.Seq["MainSequence"].Main["MyActionStep"] gives the reference to a step named MyActionStep in the MainSequence of the active Sequence File .
-RunState.SequenceFile.Data.Seq["MainSequence"].Main[0] gives the reference to the first step in the Main step group in the MainSequence of the active Sequence File .
Note that RunState.SequenceFile is a reference to the sequence file on disk and the run-time copy of the sequence being executed, which is given by Runstate.Sequence.

If the files are not open you will have to use the GetSequenceFileEx method to get a sequence file reference. Then you'd use GetSequenceByName or GetSequence to get a sequence reference. Then you'd use GetStepByName or GetStep to get the step reference. Remember that every call to GetSequenceFileEx method must be paired in the end by a ReleaseSequenceFileEx when you are done with the sequence file reference.

Once you have the step reference you need to clone it with the Clone method. You then use the SetPropertyObject method to insert the clone in your target sequence.
To do this you will have to have a reference to the target sequence. You may already have a reference available in the property paths (depends on your target) or you may need to use GetSequenceFileEx, GetSequenceByName or GetSequence, and ReleaseSequenceFileEx to get a target reference.

After you make the change to the target you should call the IncChangeCount method on the sequence file containing the target sequence. This informs TestStand that a change to the file has been made.

You can then use the Save method to save the target sequence file.

Without knowing the details of your application it is difficult to give anymore specifics a solution.
0 Kudos
Message 2 of 2
(3,118 Views)