Scripting: How to get an IM "file" from and IMimage?

Started by ubacher, February 16, 2015, 07:11:42 AM

Previous topic - Next topic

ubacher

Scripting problem:
If I create an image in my script I can save this image as a file to disk.
To manipulate this new file further inside the script I have to get the file
added to the db first and then read it. I don't see any way of doing this.

If I use automatic indexing the file will eventually get added - but then I
have no easy way of knowing inside the script when this has happened.

Background: I am adding borders to images so as to make the resulting image have a fixed format i.e. w/h ratio.

Possible work-around:
I could copy the files first into a temporary folder (inside IM), rename them and then
do the image manipulation and write the files out under the same name. Would that work?

Mario

When you create/update a file on disk, IMatch will scan it in the background at some later time. You cannot tell when this happens, because IMatch may be busy doing other things, scanning other folders or whatever. It's completely asynchronous.

You can write your script to check occasionally for the file, using the Database.Files collection (you can lookup files via their file name, see the help). Set a timer in your script and poll every couple of seconds.

Another idea would be to use the Database script to check for OnFileAdded events.
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook

ubacher

So if I do manual file indexing I am stuck and have to exit the script.


If I use the workaround by copying and renaming the files before modifying them I should be able
to add categories and set attributes which will then show in the files once updated. (Correct?)


Mario

QuoteSo if I do manual file indexing I am stuck and have to exit the script.
When you deliberately disable the background indexing, IMatch will not pick up new files automatically. You need to refresh the folder manually or using the AddFolder method of the database class. Or react on the OnFileAdded event. Or poll the database every n seconds to see if your new file has been added (automatic rescan must be on).
-- Mario
IMatch Developer
Forum Administrator
http://www.photools.com  -  Contact & Support - Follow me on 𝕏 - Like photools.com on Facebook