In this article today I will show you 5 tips and tricks with MBS that can make your life easier. I wish you a lot of fun with it.
Did you know that with the MBS FileMaker Plugin you can open files directly by script function? This is possible with the function Files.LaunchFile. In the parameters we specify the path to the file that should be opened.
Set Variable [ $r ; Value: MBS("Files.LaunchFile"; "/Users/sj/Desktop/abc.png")
If you want to open a file from a container, you first have to take a small indirect route, e.g. we store the files in the temporary folder. For this we first use the function Folders.UserTemporary which gives us the file path to the temporary folder. With the function Container.GetName we can find out the name of the file which is in the container. These two components are then merged to a path where we can then place the file with the function Files.WriteFile to open this file again with Files.LaunchFile.
Set Variable [ $PathTemp ; Value: MBS("Folders.UserTemporary") ] Set Variable [ $FileName ; Value: MBS("Container.GetName"; OpenFile::Container) ] Set Variable [ $FilePath ; Value: MBS("Path.AddPathComponent"; $PathTemp; $FileName) ] Set Variable [ $r ; Value: MBS("Files.WriteFile"; OpenFile::Container; $FilePath) ] Set Variable [ $r ; Value: MBS("Files.LaunchFile"; $FilePath) ]
We also have a new function that helps you delete these stored files when you don't need them anymore. With the new function Files.DeleteLater. This function creates a list of file paths that are deleted after FileMaker is closed. This keeps your folders clean.
Do you want to have more security when entering IBAN numbers? Then MBS has something for you. With the component IBAN you get some functions that can be useful for IBAN handling. First of all we can format an IBAN to make it more readable for a user. For this we use the function IBAN.Format. If we want to use the IBAN without spaces, we can use the IBAN.Compact function. We can use the function IBAN.CalcCheckSum to get the checksum from an IBAN. The checksum is the two digits after the country code of the IBAN. If we don't know this, we simply enter these two numbers with 00 and the function determines the checksum for us, wich we can insert there. In addition, with IBAN.IsValid we can also validate an IBAN number, i.e. check whether it corresponds to a certain scheme that is defined for the country to which the IBAN belongs. With this function you don't check if the IBAN exists, but if it has the right format. This check is done with a so called RegEx, which you can also get for each country by specifying the country code with the function IBAN.RegEx.
Do you know this? You want to save a file in a container field that your users can freely select and the possibilities FileMaker offers you are not enough, then MBS can help you. MBS has functions to customize open and save dialogs to your needs. The settings for the dialog are set in FileMaker for all scripts. That means you can make the settings for your dialog in one script and then call it in another script. On the other hand, it also means that if we set up a completely new dialog, we have to make sure that we get rid of the old settings first. For this we have the function FileDialog.Reset. That resets all settings to the defaults. First you can set the title of the dialog with FileDialog.SetWindowTitle. Then the text that is displayed in the dialog with FileDialog.SetMessage. This can also help you to give the user more precise instructions on which file to select. You can also specify the text of the default button with FileDialog.SetPrompt. If you want to start searching for the right file in a specific folder, FileDialog.SetInitialDirectory will help you. Furthermore you can use FileDialog.SetFilter to set filters for the file selection. This prevents e.g. that you open a text file, even if a picture was desired. Also if you want to select one or more files at the same time, you can set with FileDialog.SetAllowMulti function. For displaying a dialog use one of the following functions according to the dialog type you need: FileDialog.OpenFileDialog, FileDialog.SaveFileDialog, FileDialog.SelectFolderDialog or FileDialog.SelectItemDialog.
Do you know this? Sometimes you want to crop images squarely when you want to insert them into a square container. This is also possible with MBS. For this you use the functions from the GraphicsMagick component which deals with all functions around images. First we can load an image from a file (GMImage.NewFromFile) or a container (GMImage.NewFromContainer) into our working environment. Then we determine the height and width of the original image. We distinguish our procedure for portrait and landscape format. If we have a landscape format, we want the original height to be the side length of the cutout. Next we have to decide what the offset of the section is. In landscape format it is zero at y, because we do not have to move away from the top edge. How much we need to move away from the left margin we calculate. We want to have the section in the middle, that means we first subtract the image size from the complete width, so that only the size of the piece we don't want to have remains. The distance should now be the same on both sides. So we divide the value by 2 so that right and left are cut away equally. This is then the offset of X. For portrait format we simply turn the principle around. The X-Offset remains at 0 and Y is composed as just described for the Y-Offset. Now we can assemble the geometry that we will use in the GMImage.Crop function that creates the cutout. First we specify the width x height and then the offset for X and Y connected with a plus. The image is written into a container after it has been cropped and the working environment is released again.
Set Variable [ $img ; Value: MBS( "GMImage.NewFromContainer"; OpenFile::Container ) ] Set Variable [ $h ; Value: MBS("GMImage.GetHeight"; $img) ] Set Variable [ $w ; Value: MBS("GMImage.GetWidth"; $img) ] If [ $h ≤ $w ] Set Variable [ $size ; Value: $h ] Set Variable [ $OffsetX ; Value: ($w-$Size)/2 ] Set Variable [ $OffsetY ; Value: 0 ] Else Set Variable [ $size ; Value: $w ] Set Variable [ $OffsetX ; Value: 0 ] Set Variable [ $OffsetY ; Value: ($h-$size)/2 ] End If Set Variable [ $Geometry ; Value: $Size & "+" &$OffsetX& "+" &$OffsetY ] Set Variable [ $r ; Value: MBS("GMImage.Crop"; $img; $Geometry) ] Set Field [ OpenFile::Container Output ; MBS("GMImage.WriteToContainer"; $img; "abc.png") ] Set Variable [ $r ; Value: MBS("GMImage.Release"; $img) ]