In this article we want to introduce you the new functions from the MBS FileMaker Plugin in version 14.0.
DynaPDF
Let's start with DynaPDF. DynaPDF has received new parser functions. With these functions you can search for text on a PDF page and then delete or replace it. For example, if you already have an imported page, you can create a parser object with DynaPDF.Parser.Create. With the function DynaPDF.Parser.SetAltFont we can then set an alternative font. With DynaPDF.Parser.ParsePage we parse a page and store the page contents in an objects internally.
Now we can call various functions, e.g. to find the text. With DynaPDF.Parser.FindText we can search for a specific text on the page. In this function we then specify the desired search mode, e.g. you can decide whether you want to perform a CaseSensitive or CaseInsensitive search. There is also a parameter that is particularly useful if you have longer texts. This is because you can decide whether you always want to start at the beginning of the text or whether you want to continue searching from the last position. If you have previously used the DynaPDF.Parser.FindText function, you can now use DynaPDF.Parser.SelectionBBox to determine where the found text is located on the page. We thus receive a list of coordinates that describe a box around the location where the text was found.
For example, we can draw a rectangle around the match to mark it. Instead of marking the text, we can also replace the found text with DynaPDF.Parser.ReplaceSelText. Of course you can also delete the found text. To do this, either enter an empty string in DynaPDF.Parser.ReplaceSelText or delete the text using the DynaPDF.Parser.DeleteText function, which deletes text from an area defined by coordinates. To do this, we pass the coordinates that we receive with the DynaPDF.Parser.SelectionBBox function.
You can then use the DynaPDF.Parser.WriteToPage function to write these changes back to the PDF page.
If you want to get the parsed text of the page, you can use DynaPDF.Parser.ExtractText after you have called DynaPDF.Parser.ParsePage, which will return the text.
If you are particularly interested in this topic, please take a look at our new example Find and Replace Text.fmp12.
Let Randomness Decide
We have added three new algorithms in the Math section that generate random numbers. You can choose from the normal distribution, expotentail distribution and Poisson distribution. You can also specify the mean or lambda in each function to further influence the function. Math.Random.NormalDistribution then returns random numbers according to the Normal (or Gaussian) random number distribution. Math.Random.ExponentialDistribution a random non-negative floating-point number, distributed according to probability density function and Math.Random.PoissonDistribution gives you a non-negative integer value, distributed according to discrete probability function
In line with the topic of randomness, you now also have the option of randomly sorting the entries in your List and QuickList. The functions List.Shuffle and QuickList.Shuffle are available for this purpose.
Matrix
The new Matrix.IndexOfFirstValueMatching function allows you to determine the index of the first value in a matrix that matches a search. In the function, you first specify the matrix reference, then the column in which we want to search for the value, followed by the operator with which the subsequent value is to be matched. The operator can be =, !=, <, >, <=, >=, ≤, ≥, ≠, Prefix or Postfix. Optionally, we can specify a last parameter, the row in which we start the search.
Let's imagine we have a 3x3 matrix that looks like this.
23 | 12 | 65 |
---|---|---|
45 | 120 | 4 |
66 | 87 | 82 |
We now want to find a value in the second column that is greater than 100. We can use the corresponding script to do this.
Set Variable [ $Matrix ; Value: MBS("Matrix.New"; 3; 3) ] Set Variable [ $r ; Value: MBS("Matrix.SetRow"; $Matrix; 0; "23¶12¶65") ] Set Variable [ $r ; Value: MBS("Matrix.SetRow"; $Matrix; 1; "45¶120¶4") ] Set Variable [ $r ; Value: MBS("Matrix.SetRow"; $Matrix; 2; "66¶87¶82") ] Set Variable [ $r ; Value: MBS("Matrix.ConvertDataType"; $Matrix; "Number") ] Set Variable [ $res ; Value: MBS("Matrix.IndexOfFirstValueMatching"; $Matrix; 1; ">"; 100) ] Show Custom Dialog [ "Index Of First Value Matching" ; "The index is " & $res ]
And this is the result:
The 120 corresponds to the criteria. As you can see in the script, you must first specify that the values within the matrix are numeric. Otherwise the values will be seen as text by default and the result may be incorrect.
FM.SQL
While we are on the subject of matrices, I would like to introduce you to another function. The function FM.SQL.ToMatrix allows you to write a result set received from FM.SQL.Execute to a matrix so that you can further process this result set with the matrix functions, for example.
Phidget
Last year we added the new component Phidget to the plugins. With the plugins you can control these small input/output devices of the Phidget brand. In this release, we have again added new functions to this component. On the one hand, we have the functions Phidget.SetTag and Phidget.GetTag with which we can set an additional tag, which we can then query again at a later time. This can be, for example, a data set ID that is linked directly to the Phidget.
We also have the new functions Phidget.EnableServerDiscovery and Phidget.DisableServerDiscovery. You can start a server discovery to find remote devices. A Phidget can be connected to a wireless hub that sends all data via Ethernet or Wifi to a computer in the local network. To connect to remote Phidgets, call the Phidget.EnableServerDiscovery with server type DeviceRemote. But for other uses you also have Pass none, deviceListener, Device, WWWListener, WWW, WWWRemote or SBC as types. To Disables the dynamic discovery of servers that publish their identity you need to call Phidget.DisableServerDiscovery.
CURL
Also new in the plugin are some CURL functions that refer to successes or failures in the transmission. You can now set a script or an expression that is called on success or failure in the transfer. For success, the functions CURL.SetSucceededEvaluate and CURL.SetSucceededScript are available. For failure, the functions CURL.SetFailedEvaluate and CURL.SetFailedEvaluate. In addition, we also have functions that give us information about the called script or expression.
JSON
With the new release, you have the option of creating and using Patch and MergePatch for JSON. Patch and Merge Patch are formats used to describe changes to a JSON. With the functions JSON.MergePatch.FromDiff and JSON.JSONPatch.FromDiff functions, you can record these changes between two JSONs. Both have a different way of dealing with these changes as you can see here:
You can then apply the changes described by this patch to a JSON using the functions JSON.JSONPatch.ApplyPatch and JSON.MergePatch.ApplyPatch.