03-12-2019 05:21 AM
Hello,
I use VBAI API in c#. Is there any possibility to get value of variables?
Solved! Go to Solution.
03-12-2019 09:07 AM
Yes. You need to call "EnableInspectionMeasurements" so the engine will know to keep track of results, and then after you run an iteration, you can call "GetInspectionMeasurements" to get the results.
If you want to get specific results, you will need to pass in an array of GUIDs. To get the GUID for the specific variable you want, call engine.GetStepGUIDFromName("Variable", "<Variable Name>", out myGUID); and this will populate the myGUID string so you can pass it to the GetInspectionMeasurements.
Hope this helps,
Brad
03-12-2019 09:54 AM
Thanks. It works.
string variableGuid; engine.GetStepGUIDFromName("Variable", "Test", out variableGuid); var t = engine.GetInspectionMeasurements(new string[] { variableGuid }, out timeStamp); var strValue = ((StepMeasurements)t[0].measurements.GetValue(0)).measurement.strData;
I have next question. Is it possible to set value of variable via code? From c# to VBAI ?
03-12-2019 10:19 AM
Yes, use the SetVariables method.
03-13-2019 03:24 AM
Do you mean this method? Because it doesn't work.
public void SetVariables(VariableUpdateMode updateMode, VariableValue[] variableArray); //VBAIEngine
03-13-2019 09:15 AM
Make sure you set all three parts of the VariableValue for each item in the array (i.e. name, type and the corresponding value)
For example:
VariableValue[] arrayValues = new VariableValue[1];
arrayValues[0].name="Test";
arrayValues[0].type= VariableDataType.NumericVariableType;
arrayValues[0].numValue=3.33;
engine.SetVariables(VariableUpdateMode.UpdateImmediately, arrayValues);
This will set a numeric variable named "Test" to 3.33 the next time the inspection is run. Make sure the variable name exactly matches what you have in VBAI.
Hope this helps,
Brad