HALO-Photographs VB-Script for Expression Media2 to execute ExifTool HALO-Photographs

VB-Script to execute ExifTool in Expression Media2

Expression Media2 from Microsoft offers a very convenient interface to 'Virtual Earth' from Bing for geotagging one or many images. Simply drag them into a window with a map and drop them onto the exact location you want them to be. As simple as it can get, that's great - not new, but still great.
For hours a was happily geotagging a great bunch of images. Then I became curious to know where that geodetic information really went. After synchronizing the annotations to the image files, I went to see what's now inside that image file.
To my surprise there was no sign of geodata around. Well probably because I am using Nikon .NEF files and Expression Media does support writing all the annotated information into Nikon .NEF files. As a fact GPS-Longitude and -Latitude are not written into a .NEF file - What a bummer. (Note: I have not checked this issue with other file formats.)
The obvious question of 'How to move that GPS data to where it belongs to?' arised. To keep back-up copies of catalogs is not the solution as I rather have a proper back-up for my images.
Expression Media2 offers to export the database into XML-format. A great thing and the data is all there - except Expression Media2 missed out on the functionality of properly importing its own exported XML-data. As a fact GPS-Longitude and -Latitude are not written back into the catalog. So again, this cannot be a solution either.

I am convinced that all image data eventually and permanenty belongs into the image itself - and nowhere else.
ExifTool has proven to be the master to help getting out of the disaster. So I started to write a script, that:
- reads tediousley gathered geodetic information, in this case only Latitude and Longitude
- then calls ExifTool to write this data into the EXIF header of the currently selected file(s).
This is not a 1:n copy, this script does it 1:1 for each image with its own various GPS coordinates (Lat/Long).

With this script the annotated values for Longitude and Latitude are where they belong to - inside the image(s), hence valid backup candidates. In case disaster strikes, rebuilding an image catalog becomes less a pain.

For any other image formats, one must adapt the script and/or the command-line to your own gusto. One needs to know what ExifTool should do and apply changes accordingly. So you better feel comfortable using an editor and - more important - know somewhat how to use ExifTool in the first place.
Remember, the code in this example does the job for NIKON .NEF files.
That's all - here is the code, enjoy:

An experienced coder for Visual Basic may certainly improve the script to become more efficient, but for now I am quite happy the way it works.

'Script by Hans Loepfe, www.halo-photographs.com, May 2010
'Creative Commons License: BY-NC-SA https://creativecommons.org/licenses/by-nc-sa/2.5/ch/
'Script expects 'Exiftool.exe' in '%root%\Windows' or in 'path'.
'Script assumes Latituderef=North and Longituderef=West
'ExifTool by Phil Harvey: http://www.sno.phy.queensu.ca/~phil/exiftool/
'Consult the ExifTool Application Documentation: http://www.sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
'Consult the ExifTool FAQ: http://www.sno.phy.queensu.ca/~phil/exiftool/faq.html
'By using this script, you agree to use it at your own risk. 

Option Explicit 

Const BoxTitle = "Expression Media - ExifTool" 
	Dim ivApp, ExifApp, Exec, Cat, mediaItem, quote, PathFile, cmdline, x, y, vbl, original
	q = (chr(34))				'set the quote character into a constant. This is needed for the PathFile sring
	x = 0					'itmes processed
	y = 0					'items total
	vbl = "-v2"				'Exiftool verboose level
	original = "-overwrite_original"	'use this only when you're really sure about what you're doing.

	Dim iptclat, iptclong

If (MsgBox("For each selected media item(s), ExifTool is run according to the parameters supplied.",1, BoxTitle) = vbOk) Then
	Main() 
End If 

Sub Main() 
Set ivApp = CreateObject("ExpressionMedia.Application")
Set Cat = ivApp.ActiveCatalog 
Set ExifApp = CreateObject("WScript.Shell") 

If (ivApp.Catalogs.count = 0) Then 
	MsgBox "Please launch Expression Media.", vbCritical, kBoxTitle 
End If 

If (Cat.Selection.Count = 0) Then 
	MsgBox "You need to select at least one media item in the active catalog in order to use this script.", vbCritical, BoxTitle 
Else 
	For Each mediaItem In Cat.Selection
	y = y+1
	if ( mediaItem.Annotations.Longitude <> "" ) then
		'read Lat/Long from Image Database
		iptclat = mediaItem.Annotations.Latitude
		iptclong = mediaItem.Annotations.Longitude
		PathFile = quote & mediaItem.Path & quote	'a string with spaces, like a path with filename, must be quoted
			'msgbox quote				'double check you've got the right 'char' that displays a ["].
			'msgbox PathFile			'view the actual path statement
			'carefully examine and edit the 'cmdline' below as per your requirements to run exiftool with parameters 
			'use /k to leave the Window open or /c to close the window after command-execution
			'exiftool -gps:GPSLongitude=<iptcLong> -gps:GPSLongituderef=W -gps:GPSLatidude=<iptcLat> -gps:GPSLatituderef=N <PathFile> <vbl> <original>
		cmdline = ( "%comspec% /k exiftool -gps:GPSLongitude=" & q & iptcLong & q & " -gps:GPSLatitude=" & q & iptcLat & q & " " & PathFile & " " & vbl)
			'double check your command-line before shooting at live data. copy-paste and first try with test-image
			'inputbox "command line",, cmdline
		ExifApp.Run(cmdline)				'execute ExifTool according to your entries in 'cmdline'
		x = x+1						'this counter may be usefull when using 'if' conditions above
	end if
	Next
	MsgBox "found: " & x & " / processed: " & y , vbOKOnly, "Result"
End If 
End Sub

resources:

ExifTool by Phil Harvey: https//sno.phy.queensu.ca/~phil/exiftool/
ExifTool Application Documentation: https://sno.phy.queensu.ca/~phil/exiftool/exiftool_pod.html
ExifTool FAQ: https://sno.phy.queensu.ca/~phil/exiftool/faq.html
Archived Blog from the 'Hey scripting Guy' helped me to get started: Hey, scripting Guy

HALO-Photographs contact HALO-Photographs HALO-Photographs