Smart Recipe Examples
The "Smart" type Recipe is an engine that allows users to load and save values within a text document. It allows the user to anchor values and link it to tags. Then it is possible to save and load different values.
It can be used to create an interface with external software ,for example. Let's say this external software is loaded with a pre-defined text file (image below).
Now the smart recipe will be configured to send customer information to the external software, and it may return other customer information to maintain the synchronization.
This can be done by anchoring each value to application tags.
For this example, we will look at the "Customer Number". Its value will be the "Anchor Value". This value will be linked to a tag in the properties window and then you will need to create the anchors to make it unique in the document. You can use 3 anchors to identify uniquely the customer number value. In this example above, we chose the words "Customer" as First Anchor and "num" as Second Anchor.
It will show in the properties window:
Customer Number
Tag: Customer (type string)
Type: Value
Anchor Value: Line 0
First Anchor: (Text = Customer) Line 0 and Token 1 (first token/word of the anchor line)
Second Anchor: (Text = num) Line 0 and Token 2 (second token/word of the anchor line)
Tax Table
Tag: TaxTable[4][4] (float matrix)
Type: Matrix
Anchor Value: Line 0
First Anchor: (Text = Tax) Line -1 and Token 1 (first token/word one line above of the anchor line)
Example 1: Smart Recipe - Anchor Value Type.
1- Create a data type (dt_SmartRecipe) with the following configuration:
2- Create a tag associated to this new data type.
3- Create a new recipe.
4- Change the Recipe type to Smart Recipe.
5- Create a Text Document, such as the example below:
Save it to "c:\externalDocument.txt"
6- Select the "externalDocument.txt" in
the Recipe Path field.
The file will be loaded to the Editor's
box.
Now configure the trigger to Save and Load. These tags were created in the data type.
7- Anchor the "Customer num"
Open the properties window.
Go to the first item (or add a new one if needed)
Add the tag "objSmartRecipe.CustomerNum" to the Tag field.
Go to the text editor and double-click the value "12351".
Right-Click with the mouse and select "Anchor Value".
This will add the value to the properties window (Value anchored field).
Now you need to add Anchors to make it unique.
Insert the word "Customer" to add as "First Anchor".
- You can create 3 anchors for each Value, but in this example, we will need only one.
- Please see the image below. The first anchor "Customer" refers to Line 0 and Token 1, what means it is in the same line of the Anchored Value and it is the first token of the line.
- The Editor will show the "First Anchor" highlighted with green. It means the anchor is unique and you do not need to anchor any more texts.
- If the color was yellow, it would have meant we still needed to add a second anchor or maybe a third anchor to make this value unique.
. Now let's run a test.
. Run the Application (F5) and see the results.
. Open the Data Watcher.
. Add the 3 tags to the data watcher as in the image bellow
. objSmartRecipe.trgSalvar
. objSmartRecipe.trgCarregar
. objSmartRecipe.CustomerNum
. First let's load the value from the text file.
. Change the value of the load trigger "objSmartRecipe.trgCarregar" from 0 to 1 (trigger).
. Watch the value "12351" will be loaded to our anchored tag "objSmartRecipe.CustomerNum".
. Now let's write some other value back to the file.
. Write 44444 to the tag objSmartRecipe.CustomerNum
. Change the value of the trigger "objSmartRecipe.trgSalvar" from 0 to 1
. Open your text file and check if the CustomerNum was changed.
Example 2: Smart Recipe - Anchor Matrix Type.
. Using the same steps as the previous example:
. The "externalDocument.txt" will be used with the same values.
. We will have a data type to represent the information in the "externalDocument.txt".
. Now we will use the tag "objSmartRecipe.TaxTable". This tag will be anchored to the first index of the table -> [0,0]
. Please see below the table. Lines 1 and 2 are highlighted because we will change its value later in this example.
. Configure the following:
. Tag = objSmartRecipe.TaxTable
. Anchor Value = First row and first line value (value 1 on the table).
. First Anchor = We can use the text "Tax" which appears only once in the entire document and will make this anchoring unique. There will be no need to add a second anchor.
. Limiters: [x] Until the end (We can limit the size of the matrix or try to get the entire table. The size of the tag must be enough too.)
. The configuration should look like the image above.
. See the "Tax" word is highlighted with Green, which means the anchor is ok and unique.
. Now let's run a test.
. Run the Application (F5) and see the results.
. Open the Data Watcher.
. Add the 3 tags to the data watcher as in the image below.
. objSmartRecipe.TaxTable
. objSmartRecipe.trgSalvar
. objSmartRecipe.trgCarregar
. Let's try to Load the table to the tag.
. Change the value of the trigger "trgCarregar" from 0 to 1
. The table will be loaded to the tag as you can see in the image below.
. Now let's write some values back to the file.
. In the data watcher, we changed the values of the first 2 rows (please check the image below).
. Then change the write trigger's value from 0 to 1 (objSmartRecipe.trgSalvar)
. It will change our document:
Related Recipe sections: