EXIF TOOL API FUNCTIONS USABILITY WITH VISUAL BASIC OR VBA ?

Started by ULSWK, September 12, 2011, 02:19:49 AM

Previous topic - Next topic

ULSWK

Hi all.
is it possible to access EXIF TOOL Functions with Visual Basic .NET or Visual Basic for Applications ?
I wrote several personal helper utilities supporting my workflow using VB.
Is there any possibility ?

Ulrich


Phil Harvey

...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

ULSWK

Thank's Phil,
I will try out these examples this evening.
Your tool is very helpful.

Ulrich

baldmosher

I've started doing a bit of this.... trying to add tags to a bunch of scanned match tickets that already have the date as the filename.  Before I upload them to Facebook/Picasa/Flickr I want to add the relevant EXIF datestamps.

Firstly I output with "-all" to a CSV file using command line, then discovered that if the tag is missing from all of the files, exiftool just ignores it...so I manually added the relevant tags to one of the files, deleted the CSV file, and then repeated the process.

exiftool -all -csv *.* > out.csv

I then simply copied the date tags in the same format down the whole column in the CSV for all the other files (rows), amending the relevant dates as I went along.

The rest was a little bit of VBA.

You'll need to get the Shell And Wait module by Chip Pearson (Google it, or it's included in the attached xls) as this is more reliable than simple Shell commands (can sometimes overlap, causing file locking write errors).  You could just use Shell command instead (but remove the extra comma before vbHide)

Then the rest is just a first example, insert a new module in VBA and copy the following code:


Option Explicit

Sub exif_write_createdateANDdatetimeoriginal()

Dim fn As String, dt As String, d As Byte, c As Byte, v As Range
d = Application.Match("DateTimeOriginal", ActiveSheet.Rows(1), 0)  'find the column number in the CSV sheet
c = Application.Match("CreateDate", ActiveSheet.Rows(1), 0)

Const pth As String = "V:\My Files\Pictures\EXIF untagged\"   'set this to your path, include the trailing \
Dim exifexe As String
exifexe = Chr(34) & pth & "exiftool.exe" & Chr(34)   'could change pth to refer to a different folder but in this example it's in the same folder

For Each v In Selection.Cells    'highlight all the FILENAMES in column 1 of the CSV file that you want to process
    fn = Chr(34) & pth & v.EntireRow.Cells(1).Value & Chr(34)
    dt = Chr(34) & v.EntireRow.Cells(d).Value & Chr(34)  'I'm using dt for both tags
    ShellAndWait exifexe & " -xmp:dateTimeOriginal=" & dt & " " & fn, , vbHide
    ShellAndWait exifexe & " -xmp:CreateDate=" & dt & " " & fn, , vbHide
Next v

End Sub


You can easily substitute the above tags for other tags, and with minimal playing around you can replicate this for most purposes.

For testing, just add " -k " into the shell command and remove vbHide, test it with one file, it'll keep the CMD window open and visible.

Phil Harvey

Sounds good.  Just one comment:

Quote from: baldmosher on January 31, 2013, 06:55:01 PM
Firstly I output with "-all" to a CSV file using command line, then discovered that if the tag is missing from all of the files, exiftool just ignores it...so I manually added the relevant tags to one of the files, deleted the CSV file

Another approach is to use the -f option and specify the tags you want to extract in the command, probably using the -@ option if there are many of them.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).