Accessing Properties and Results in SPEL+: VGet, VSet
The VGet and VSet commands can be used to read and set sequence and object properties in SPEL+ programs.
For example, you can change a search window size and location, an accept parameter, camera gain, and maximum area to name a few.
Nearly all of the properties and results that can be accessed from the Vision Guide 8.0 point and click interface can also be accessed from a SPEL+ program. There are also some special properties that can only be accessed from using VSet or VGet since they set or return multiple results. (e.g. SearchWin, RobotXYU, and ModelWin to name a few.)
A common syntax is used for both VGet and VSet.
Each command must first refer to the name of a sequence. In addition, the name of a vision object must follow the sequence name in order to access properties and results for vision objects.
A period is used to separate the sequence, object, and property or result name. If multiple results are used, specific results are selected by appending the result number in parenthesis after the result Name.
For sequence properties and results, the following syntax is used:
VGet seqName.propName, var ‘put property value in variable
VSet seqName.propName, value ‘set property to value
For object properties and results, the following syntax is used:
VGet seqName.objName.resultName, var
VGet seqName.objName.propertyName, var
VSet seqName.objName.propertyName, value
For object multiple results, the following syntax is used:
VGet seqName.objName.resultName(resultnum), var
The sequence and object names can also be string variables.
Refer to the following for details.
Using Variables for Sequence and Object Names
Using VGet
VGet retrieves a property or result and puts it in a SPEL+ variable. You must supply a variable in your program of the proper data type to receive the value from VGet.
Here is an example of using VGet in a SPEL+ program.
Function Inspect
' Run the vision sequence
VRun InspectPart
Integer i, numberFound
Real area
VGet inspPart.Part1.NumberFound, numberFound
For i = 1 to numberFound
' Loop through each item that was found
' Get the area of the blob result
VGet inspPart.Part1.Area(i), area
Print "Area of result ", i, " is ", area
Next i
Fend
Using VSet
VSet sets a property value at runtime. This allows developers to dynamically adjust property settings from a SPEL+ program.
In most cases you can set property values from the Vision Guide window and then run vision sequences from SPEL+ programs with no modifications of the properties. However, for those cases that require dynamic adjustments, the VSet SPEL+ command can be used.
Here is an example of using VSet in a SPEL+ program. Notice that the first call to VSet sets a sequence property. The second call to VSet sets an object property called SearchWin that is used to re-define the position and size of a search window before running the sequence.
Function findPart
' Set camera gain for sequence "findPart"
VSet findPart.CameraContrast, 32
' Set search window for object "part"
VSet findPart.part.SearchWin, 100, 100, 50, 50
' Run the sequenced
VRun findPart
Fend