Product Logo

CNS Image

Import, edit, and export Images in the FileMaker environment

Coding Considerations

##Getting Results

When calling the plug-in through functions or some script steps, you can get information back from the plug-in about what it is doing. How you get results depends if you are using functions or script steps to call the plug-in.

###Functions Every time you use an CNS Image function, status text is returned back from the plug-in. This information can be very useful for letting you know if an error occurred. Consider the following:

Set Field[ db::result ; CNSImage_File_Delete( “C:\Folder\01.png” )]

The above code will delete the “file.ext” file. If it was successful, the plug-in will return the following to the db::result field:

Deleted: C:\Folder\01.png

However, if there was an error with the delete, the plug-in will return something like the following to the db::result field

ERROR: File_Delete: File does not exist.

###Script Steps

Not all of the plug-in’s script steps return results. Whether the script step will return something is determined if it has the “Target” parameter. This script step parameter allows you to specify a Field or Variable to hold the result data. For example, consider the Rotate script step:

CNSImage Rotate [ Target: Images::N ew ]

When you select the CNSImage Rotate script step and view the parameters of the step, the Target parameter specifies where the result image will go. In the example above, after the script step is run, the “Images::New” field will contain the new image that was rotated.

##Error Checking

Including error checking in your scripting is vital to writing robust email scripts that will not break when something does not work correctly. How error checking is implemented depends if you are using the functions or script steps.


For error checking when using the plug-in’s functions, consider the following:

Set Variable[ $delete ; CNSImage_File_Delete( “C:\Folder\01.png” )]

The above code will delete the “01.png” image file. If it was successful, the plug-in will return the following to the $delete variable:

Deleted: C:\Folder\01.png

However, if an error occurred for any reason, the plug-in will return the error to the $delete variable. For example:

ERROR: File_Delete: File does not exist.

Notice the error begins with “ERROR:”. Since all errors begin with this, you can write your scripts to look for this string. For example:

Set Variable[ $delete ; CNSImage_File_Delete( “C:\Folder\01.png” )]
If[ PatternCount( $delete ; “ERROR:” ) > 0]
Take action here like:
Show Custom Dialog[$delete]
Set Field[ db::result ; $delete ]
Halt Script
End If

What your script does when an ERROR is encountered really just depends on what you want the script to do. In the above code, the script writes the error to the database using a Set Field script step, displays the error to the user via a Show Custom Dialog script step, and then Halts the script.

Writing errors to the database via Set Field is very important when using Set Variable script steps to call the plug-in. If an error occurs when using Set Variable, and you do not write the error to the database, the error message will be lost as soon as the script finishes.

###Script Steps

For error checking when using the plug-in’s script steps, consider the following:

CNSImage File Delete [ File: “C:\Folder\01.png” ] 

The above script step will delete the “01.png” image file. To determine in an error occurred with the delete, call FileMaker’s Get ( LastError ) function, and then you can get the actual error by calling FileMaker’s Get ( LastExternalErrorDetail ) function. With this in mind, error checking for the plug-in’s script steps could look like:

CNSImage File Delete [ File: “C:\Folder\01.png” ]
If[ Get ( LastError ) ]
Take action here like:
Set Field [ Images::Error ; Get ( LastExternalErrorDetail ) ]
Show Custom Dialog [ Images::Error ]
Halt Script
End If

##Curly Brackets

When working with the plug-in’s functions, you are working in FileMaker’s calculation engine, so you must format the functions correctly for the environment. In FileMaker’s calculation engine, curly brackets indicate that a parameter or parameters are optional. Take the SMTPit_Connect function for example:

CNSImage_File_SelectWithDialog {( StartPath {; Prompt {; DialogType {; FileTypes }}} )}

This function can be called without any parameters because the parameter section is surrounded by curly brackets indicating that is it optional. Using the function in this manner looks like:


The above code would open a dialog to select a file. If you would like to specify the Starting Path that the dialog opens to, you can specify the path in the “StartPath” parameter:

CNSImage_File_SelectWithDialog ( “C:\Path” )

In more complex functions, there may be multiple optional parameters. If there are optional parameters before one that you need to use, you must include any parameters before it. Consider the CNSImage_Export function:

CNSImage_Export ( Image {; Path {; Prompt {; AllowConvert {; TypeList }}}} )

If you want to specify the “TypeList” parameter, you must also specify the one required parameter and three optional parameters before it. Following is an incorrect example and a correct example:

CNSImage_Export ( Table::Field ; “JPEG”)

CNSImage_Export ( Table::Field ; “” ; “Select a location to export the file” ; True ; “JPEG” )

FileMaker Version Considerations

When plug-ins were first introduced, the only place you really wanted to use a plug-in function was the Set Field script step. However, since FileMaker 4, many new advancements have taken place. Though the Set Field script step is still a very common place to use plug-in functions, there are now many places that can logically be used. For a list of a few of these places, see the next section titled “Places to use CNS Image Functions”.

It is important to keep in mind what versions of FileMaker will be in use when using CNS Image and other plug-ins. For example, creating a variable using the Set Variable script step can be very convenient, however, that functionality only exists in FileMaker 8 and greater. If you or your users use FileMaker 7, then your script calls would fall on deaf ears if you used Set Variable script step. In addition, when using functions in a variable you will be less likely to see the results returned from the plug-in (such as error messages), because a variable cannot but put on a layout like a field.

Places to use CNS Image Functions

You can use CNS Image functions in any calculation engine dialog in FileMaker. Keep in mind that just because you can do something does not mean it is actually useful.

There are several places that fit very well depending on the situation:

  • Calculation field
  • Auto-Enter Calculated value
  • Validation by calculation
  • Set Field Script/Button step
  • Insert Calculated Result Script/Button step
  • Show Custom Dialog
  • Set Variable Script/Button Step
  • Custom Functions
  • and more…