« Linux WebKit Support … | Home | SQLite Backup Functio… »

Accept file drops in Filemaker with MBS Plugin

This tutorial is about accepting file drops on a Filemaker window with MBS Filemaker Plugin and performing a script. We create a little database with fields FileName and FileSize. The setup looks like this in Filemaker 12:
Now we add a script to setup the drop area. So we call the DragDrop.CreateWithWindow function. We pass the window name to target the full window. If you use DragDrop.CreateWithSize, you can specify a rectangle area in the window or with DragDrop.CreateWithControl use the rectangle of an existing field. We store the reference value in the $dropview variable for use in the next lines. In second line we call DragDrop.RegisterDropTypes and specify that we want to accept files. But you also can specify images, text, URL or email. Finally in last line we call DragDrop.SetDragActionHandler to specify that the script named DragAction in our current file is called when something was dropped. The script looks like this:

In drag action script, we first pick the script parameter. This script parameter is the same value as we have in the $dropview variable in the other script. But as you can have multiple drop areas, this parameters gives you a possibility to know which one was hit. Also we need this value for calling DragDrop.GetPath. So we have now the first path in the variable $path. This path is now stored in FileName field and also we call Files.FileSize to get the file size.

Now you can test it. Simply drop a file on the window and you see path and file size in the database window:

Download plugins here and the example database: dragtest.zip
20 08 12 - 20:50
three comments

Thanks for your sharing.i like your post very muh and learn a lot information from your article,thanks.
wholesale nhl jerseys - 25 08 12 - 05:29

Question — if (or how) does MBS Plugin handle multiple-item drag & drop?

For example, if I select 10 image files at once in the Finder, and want to drag/drop them into a Filemaker container in a Portal, can MBS Plugin gather & store the path names of each of those 10 files separately?

I would then have a Loop / End Loop script step to process each item separately in Filemaker.
Gilbert Osmond - 26 11 13 - 00:13

I think I’ve answered my own question —

I need to use MBS to count the number of paths (files) in the drag action, then, if that’s greater than 1, use a loop to gather the separate path names using MBS.

I can store those path names in a convenient place (i.e. global field(s) or variables, or regular fields within records) and then have Filemaker do other operations on a per-file / per-pathname basis.
Gilbert Osmond - 26 11 13 - 00:32

Remember personal info?

Emoticons / Textile

Hide email:

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.