Graphic Magic: Finding Files with Troi File 2.0
By Clint Roberts <clint@filemakermagazine.com>
RATING: Intermediate
PLATFORM: Macintosh & Windows
VERSION: FileMaker 3/4/5
TECHNIQUE FILE: GraphicMagic.FP3
WEB DOWNLOAD: <http://www.troi.com/>
It's a frequently asked question: "Where is it?" How many times has your fast-paced job or lifestyle distracted you from creating a directory structure and placing an important or not-so-important file in its proper place? Then again, even if you filed it properly, three months from now you won't remember the file's contents. This problem is particularly troublesome in environments where files are worth money.
For example, let's use the advertising and publishing world. This is a place where graphics files are purchased. Whether one-time or multiple-use licenses are granted, money has been transferred and the file is now intrinsically valuable.
Another example is a company's logo - not just one logo in one file, but one logo in multiple files. The logo types could also include large ones, small ones, high resolution ones, medium resolution ones, low resolution ones, color separated ones, RGB ones, CMYK ones, black and white ones. The list is long. How many times have you put together a web page or document and cannot find the right logo in the right format?
Wouldn't it be nice to always know where all of your graphic files are? How about being able to search in a database for them by category and subcategory?
The good news is you can do all of the above by using an indispensable FileMaker Pro plug-in - Troi File 2.0. To use the technique file GraphicMagic.FP3, first download and install Troi File 2.0 plug-in from <http://www.troi.com/>. Follow the installation instructions provided in the download package.
GraphicMagic.FP3 utilizes Troi File 2.0 to:
- Link a graphic file to a FileMaker Pro record.
- Create and display a Thumbnail of a graphic file.
- Display the complete path to a graphic file.
- Display the File Size of a graphic file.
- Display the File Type of a graphic file.
- Display the Creation Date of a graphic file.
- Launch a graphic file from a FileMaker Pro record.
These powerful features, combined with FileMaker Pro's ease of use, gives you the ability to store text data for notes, and perform searches on specified fields (such as Category and Subcategory). It also enables you to quickly create a database that can categorize selected graphic files.
The end result is a searchable database that contains significant detail on a catalog of graphic files. All of your graphic files can now be linked to a FileMaker Pro record that allows you to quickly search for needed files via multiple criteria.
Let's see first-hand how GraphicMagic.FP3 works.
Linking a Graphic File
Open up the technique file and click on the Link File button. An Open dialog box is displayed. Navigate to the graphic file that you wish to link to this FileMaker record. Either double-click on the file, or click once and click the Open button.
This performs the master script of this technique: Link File via Get FileSpec Dialog.
First, I turn error capture on. This enables a script to suppress error messages and customize the error message or action. Next I ensure that the FileMaker Pro client has Troi File 2.0 plug-in installed. Not doing so could result in errors if the plug-in isn't installed properly.
Editor's Note: Make sure you are using version 2.0 of Troi File. Earlier versions of this plug-in may not import graphics or open properly.
Another useful feature of Troi File 2.0 is the ability to filter what the user sees in the Open Dialog box on the Mac OS platform. If you want to be strict in which type of file formats are shown, edit the third line of the No FileType Filtering script from:
External("TrFile-SetDefaultType", "")
to
External("TrFile-SetDefaultType", "XXXX")
XXXX is the four-digit file type that you wish to display. For example, enter "SIT5" if you only wish users to attach archives created by Aladdin's StuffIt 5 technology.
I have chosen to allow showing all file types. Whereas there are multiple graphic file types that we would need to filter for, I wanted to leave the option open to allow you to test linking a file of any file type.
Set Fieldg_SelectedFile
Calculation
External("TrFile-Get FileSpec Dialog", "Please select a file:")
Next I call the Open Dialog box using the TrFile-Get FileSpec Dialog external function. The result of the call to Troi File 2.0 is placed in the field g_SelectedFile.
IfCalculation
Left(g_SelectedFile , 2) <> "$$"
This is my first error trap. All errors reported by Troi File 2.0 begin with "$$". If there is an error, the following 18 script steps are skipped (down to the second Else statement below). If no error is received, linking the file continues. If the user cancels the Open Dialog box, an error code of "$$-1" is returned.
Set Fieldg_SelectedFile
Calculation
External("TrFile-FileSpec To
FullPath", g_SelectedFile)
Using the TrFile-FileSpec to FullPath external function, the path to the selected file is placed in g_SelectedFile.
Set Fieldg_FileSize
Calculation
External("TrFile-GetFileSize",
g_SelectedFile)
I then grab the File Size using the TrFile-GetFileSize external function.
Set Fieldg_FileThumbnail
Calculation
External("TrFile-ThumbnailToClip", "-
unused |" & g_SelectedFile )
Then I use a pretty amazing function of Troi File 2.0: TrFile-ThumbnailToClip. This function works a little differently than those previously covered. Due to the nature of FileMaker Pro, a field must be set with a calculated function of TrFile-ThumbnailToClip; however, the actual thumbnail result is placed in the Clipboard.
IfCalculation
g_FileThumbnail = "$$"
Perform Script. Display Troi File plug-in Error: ThumbnailToClip
Sub-scripts
End If
Above, I make a second error trapping. If an error is placed in g_FileThumbnail, the ThumbnailToClip error script is run. Possible returned errors are:
$$-2020QuickTime not available
$$-2003No thumbnail could be created
$$-1 (Windows) function not available in this version
Set Fieldg_FileCreationDate
Calculation
External("TrFile-GetDateCreated",
g_SelectedFile)
Another useful feature of Troi File 2.0 is the ability to get the date that the selected file was created. This is especially important for keeping a historical record of graphic files. Typically, when a file is modified, it is desirable to keep a copy of the original file. Using Graphic Magic, you can attach the modified file to a new FileMaker Pro record and thus have a running list of all original and modified files. You may then determine which graphic file to use based on the creation date,
IfCalculation
Status(CurrentPlatform) = 1
Set Fieldg_FileCreator
Calculation
External("TrFile-GetFileCreator",
g_SelectedFile)
Else
Set Fieldg_FileCreator
Calculation
Right(g_SelectedFile, 4)
End If
Based on the current platform (where "1" is Mac OS and "2" is Windows), I then use two differing methods for showing the selected graphic file's type. Under Mac OS, the Troi File returns the four-digit File Type. Under Windows, the last four characters of the path name are shown. Thus, under Windows you will get ".XXX" where XXX is the file extension.
Set FieldFileSelected
Calculation
g_SelectedFile
Set FieldFileSize
Calculation
(g_FileSize / 1024) & " K"
Set FieldFileCreationDate
Calculation
g_FileCreationDate
Set FieldFileType
Calculation
g_FileCreator
Set FieldFileLinkedDate
Calculation
Status(CurrentDate)
PasteFileThumbnail
Select entire contents
The above Set Field script steps place the Troi File 2.0 values stored in Global Fields in the appropriate text, number, or date fields. Notice that before pasting the value of g_FileSize into the field FileSize, I divide it by 1024. This is because the value returned by Troi File 2.0 is a Byte unit. I have chosen to display the result as a KB (kilobyte).
Previously, I noted that the Thumbnail that was created was placed in the Clipboard. The last step above pastes the Thumbnail into the FileThumbnail field.
If an error was reported by the TrFile-Get FileSpec Dialog external function (near the start of our script), the steps below are performed (up to the End If script step).
Else
Set Fieldg_ErrorCode
Calculation
g_SelectedFile
Perform ScriptDisplay Troi File plug-in Error:
Get FileSpec Dialog
Sub-scripts
End If
First I set g_ErrorCode with the returned error. Then perform the Get FileSpec Dialog error script in which I display a custom dialog based on the number of the error returned.
Set Fieldg_ErrorCode
Calculation
""
Set Fieldg_SelectedFile
Calculation
""
Set Fieldg_FileSize
Calculation
""
Set Fieldg_FileThumbnail
Calculation
""
Set Fieldg_FileCreator
Calculation
""
Set Fieldg_FileCreationDate
Calculation
" "
Set Fieldg_FileSize
Calculation
" "
Before leaving the Link File via Get FileSpec Dialog script, I reset the Global Fields to prevent any future error traps from activating based on old data.
Launching a Graphic File
Click on the Thumbnail representation of the graphic file. Notice that the graphic file is opened in the default application that is set to handle files of the current file's File Type.
First I turn the error capture on. This will allow me to trap for errors in this process and control what type of error messages the user receives.
Next I ensure that the FileMaker Pro client has Troi File 2.0 plug-in installed. Not doing so will result in errors in the Script.
If Calculation
FileSelected = ""
Show Message
Buttons:
"OK","",""
Data:
There is no file linked to this record!
My first error trap in this Script is to ensure that a file has previously been linked to this record. If no file was previously attached, the FileSelected field will be empty. If FileSelected is empty the user is notified that no file is linked to this record.
Exit Script
Since there is no file to open, I exit the script.
Else
Set Field g_ErrorCode
Calculation
External("TrFile-Launch", FileSelected)
Since a file has previously been linked, Troi File 2.0 attempts to open it using the TrFile-Launch external function.
End If
If Calculation
Left(g_ErrorCode, 2) = "$$"
Perform ScriptDisplay Troi File plug-in Error: Launch
Sub-scripts
End If
If an error is returned, I run the Launch error script. Possible returned errors are:
$$-35 No such volume (Wrong disk name or not mounted).
$$-43 File not found.
$$-50 Parameter error.
$$-1 The file could not be opened.
Take a moment to look at the three error trapping scripts that are in the Graphic Magic technique file. I have only trapped for some of the most common errors as listed above. However, there are many more types of errors that can be encountered. Troi Automastisering has a comprehensive list of errors available in a searchable FileMaker Pro database at:
<http://www.troi.com/software/oserrrs.html>
In conclusion
While Graphic Magic highlights some of the available external functions added to FileMaker Pro by Troi File 2.0, other powerful functions are moving and renaming files. These functions added to the Graphic Magic technique file can provide for a powerful cataloguing machine that will also archive and link a graphic file at a remote server.
Have fun with the Graphic Magic technique and see how you can customize it using Troi File 2.0 to meet your specific needs!
Happy FileMaking!
Clint Roberts is a Senior FileMaker Developer for Metro Technologies in Chicago, IL <http://www.metrotechnologies.com> and the Senior Technical Editor for ISO FileMaker Magazine. Email him at croberts@metrotechnologies.com.