trouble using Application.Database.GetCacheImage()

Started by bnewman, September 07, 2014, 10:37:04 PM

Previous topic - Next topic

bnewman

I'm having trouble with using the Application.Database.GetCacheImage() method. I've read the help function, looked at the sample scripts, and forum discussions, but find no help. So here goes another post from an IMatch5 newbie.

I have a script which is processing instances "f" of "File" in a loop of "Files" obtained from selected files in a file window. I'm absolutely positive that I do have files. But when I make a call to Application.Database.GetCacheImage(f) where f is a file, I get an error "ActiveX Automation: No such property or method" at the line containing this call.

I was hoping to get the image from cache faster than using the image.Loadfile(f.FileName...) call

Hope someone can advise.

bnewman

OK, I solved my own newbie problem. The issue was not with the GetCacheImage() method, but with my misunderstanding the information in the help function. The help states "The method returns nothing when the file has no cache image and on-demand caching is disabled.". My error was to think that the method returned the value "Nothing" under unusual circumstances so the script was making a check to the effect that "image <> Nothing". This comparison expression was what was making the script unhappy. I guess if anything at all went wrong the GetCacheImage() would throw an exception (e.g. using an invalid File as input). The help information says nothing about what actually will happen in such cases. However, I do not plan on disabling on-demand caching, and the script will always be taking files that are selected in the window. So, it may not be that robust, but it will serve my needs.

By the way, now that I fixed the problem, I had hoped that GetCacheImage() would be faster than LoadImage() method of the IMIMage class. I'm disappointed that it's not. This is probably because I'm operating the script on about 480 files that have not actually been cached. Is there some way to pre-load a large number of files into cache? Or will that operation be as long as the one that occurs when operating on a bunch of files that are not cached in the first place?

Mario

Returns nothing means literally that - the Visual Basic version of a NULL pointer.

   Dim f As File
   Dim sel As Files
   Set sel = Application.GetFileWindow(imfwtCurrent).SelectedFiles
   Dim cacheimg As IMImage

   For Each f In sel

      Set cacheimg = Database.GetCacheImage(f)
      If Not cacheimg Is Nothing Then
         Debug.Print "f.FileName has a cache image."
      End If

   Next f


GetCacheImage accesses the built-in caching mechanisms of IMatch, which means that it will create cache images on-demand as needed. If you request the cache image for a file for which no cache exists yet, it will be created. Depending on the file format you use etc. this can take a couple of seconds per file.

QuoteIs there some way to pre-load a large number of files into cache?

Sure. Set IMatch to create the cache always. Or use the cache command available in the context menu of folders and files in the file window to create the cache for a folder or a selection of files in advance, overriding your cache settings. Please see the IMatch help for details about how caching works in IMatch and the commands you have available.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook