Subtle differences between scripting in Imatch 3.5 and 3.6

From ptWiki

Jump to: navigation, search

Contents






[edit] getImages for a specific filename

In iMatch 3.5, db.getImages(filename) returned an image object. iMatch 3.6 returns a collection of images to account for the fact that there could be more than one image with the name you pass.

There are many ways to handle this in your code. If you are certain that only 1 image will be returned, then the easiest way to update a script is to add a (1) after the getImages.

{iMatch 3.5}
Dim img as Image
set img = db.getImages(filename)

{iMatch 3.6}
Dim img as Image
set img = db.getImages(filename)(1)

NOTE: If no image is found, the returned collection will be empty. Use the Count method to determine if an image has been found:

Dim img as Image
Dim imgs as Images
set imgs = db.getImages(filename)
if imgs.Count <> 0 then
    set img = imgs(1)
end if

If you're not certain, then you can use a for loop to iterate over the items in the Images collection returned

Dim imgs as Images
Set imgs = db.getImages(filename)
Dim img as Image
for each img in imgs
   -- do something
next img

GetImages Parameter Modes

  1. If you use GetImages without a file name, all images in the database will be returned
  2. If you use GetImages with a fully qualified file name (including the folder name) all files with the given file name in that folder are returned. If the folder exists multiple times in the database (from different media), multiple files will be returned.
  3. If you use GetImages with only a file name, all files with that name in the database will be returned (case insensitive).
GetImages()
Returns a collection with all images in the database
GetImages("c:\images\beach.jpg")
Returns all images with the given name in the given folder. If the folder exists multiple times in the database (e.g. on multiple CD-ROMs or DVD's) multiple images will be returned.
GetImages("beach.jpg")
Returns a collection containing all images with the name "beach.jpg" in the database

[edit] Blank items in a drop-down list in a user dialogue box

This problem occurs when one of the elements in a drop-down list in a script dialogue box is blank, or has not been defined. This error came to light in the script "Import Filenames into Image Property Set", which is one of the standard scripts that ships with Imatch, and is included in the Import and Export category of scripts. The error was there up to and including V3.6.0.40, but was fixed for later versions. However, this scripting error may be in other scripts.

The problem, caused by a coding error, does does not result in any symptoms in Imatch 3.5, but it does in 3.6.

There is/was an error in the following part of the script:

Dim SelTypes(2) As String
SelTypes(1) = "Import files in the current selection"
SelTypes(2) = "Import all files in the database"

The problem with this code is that it leaves a blank element at SelTypes(0). In 3.5, SaxBasic ignores the blank element. However WinWrap Basic in 3.6 does not - it includes it in the list of options in the "What to import" dropdown, which is why this drop-down list starts with a blank when you run the script. So when you make your selection in the dialogue and press OK, the script works with the incorrect selection of images because the numbering of the choices was out by 1.

In this case, it is possible to fix the script by simply redimensioning the array and renumbering the elements:

Dim SelTypes(1) As String
SelTypes(0) = "Import files in the current selection"
SelTypes(1) = "Import all files in the database"

The important point to note is that there should not be any blank elements in arrays used to populate dropdown lists in dialogue boxes. They should start at the 0th element, and not have any gaps in numbering.

Alternatively you can set an "options" parameter so that the numbering of arrays starts from 1, rather than 0.

Personal tools