NI TestStand

cancel
Showing results for 
Search instead for 
Did you mean: 

Expression.Evaluate() - how to use it with propertyobject?

Solved!
Go to solution

Hi,

 

I code in a process model callback and would like to evaluate an expression with the Runstate.Caller context.

 

I found the method 

Expression.Evaluate ( evaluationContext, evaluationOptions = EvalOption_NoOptions)

 

This is exactly what I need. However, if I have a CallingStep.Expr, which is a expression, I can't access the Evaluate() function. It is not available, only the PropertyObjects functions are.

 

How can I cast it to be an Expression so I can access the function Evaluate?!

 

I though I could do:

Runstate.CallingStep.Expr.Evaluate(Runstate.Caller, 0x0)

 

This would return the expression evaluated in the caller context as a PropertyObject.

 

But it's not the case, I'm missing something so TS know Runstate.CallingStep.Expr is an Expression... even if I add it to Watch panel, it shows it's an expression...

 

Thank you.

0 Kudos
Message 1 of 6
(4,060 Views)
Solution
Accepted by topic author MatLaroche

Hi,

 

Try to use RunState.Caller.AsPropertyObject.EvaluateEx(xxx)

 

Hope this helps

 

Juergen

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
Message 2 of 6
(4,052 Views)

Thanks, I didn't though of do it this way.

 

This is one way to achieve it, by doing something like:

 

Runstate.Caller.AsPropertyObject.EvaluateEx(RunState.CallingStep.TS.CustomResults[1].Name, 0x0).GetValString("", 0x0)

 

This retrieves the string representing the additionnal result[1] name of my step, which is an expression using local variable in the sequence.

 

Thanks j_dodek.

 

If anyone would like to also add a comment about using Expression.Evaluate() properly or an example, it would be appreciated.

 

 

0 Kudos
Message 3 of 6
(4,049 Views)

Hi Mat,

 

Just for more understanding

you wrote:  I'm missing something so TS know Runstate.CallingStep.Expr is an Expression

 

Is this your "Expression" a Statement step Type ?  

Or is your "Expression" in every Step in Pre/Post/Status or other in stuff

 

Could  you provide a screen shot that descripes what you are looking for.

I do not understand it.

 

Regards

 

Juergen

 

--Signature--
Sessions NI-Week 2017 2016
Feedback or kudos are welcome
0 Kudos
Message 4 of 6
(4,029 Views)

I have an object of type Expression (from what I understand and from what the watch panel is showing) and I was expecting to be able to use the Evaluate() function.

 

Expression.Evaluate(seqContext, options)

 

But it seems that it's a propertyobject because only the function of this type are available.

 

I've attached a screenshot. Thank you.

0 Kudos
Message 5 of 6
(4,025 Views)

The Expression type in the API is not the same as the Expression type of a PropertyObject.  The Expression PropertyObject type really is just a "labeled" string that lets you know it's supposed to be an expression.

 

To create an API Expression Object, you need to call Engine.NewExpression.

Message 6 of 6
(4,020 Views)