Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 
Reply

VBAI 2018 - DotNet API - Get Variables

Solved!
Go to solution
Highlighted

Hello,

 

I use VBAI API in c#. Is there any possibility to get value of variables?

 

 

 

0 Kudos
Message 1 of 6
(298 Views)
Solution
Accepted by topic author JIGISTA
03-14-2019 12:44 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

Message 2 of 6
(278 Views)

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 ?

0 Kudos
Message 3 of 6
(274 Views)

Yes, use the SetVariables method.

 

0 Kudos
Message 4 of 6
(269 Views)

Do you mean this method? Because it doesn't work.

public void SetVariables(VariableUpdateMode updateMode, VariableValue[] variableArray); //VBAIEngine

0 Kudos
Message 5 of 6
(258 Views)

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

0 Kudos
Message 6 of 6
(254 Views)