Hi,
I posted a script here. Please read the script thread to know what it does.
After some test, there is a bug returning no error: If you select only image files, it will work properly as intended. But if among the selected files there are other file types, the script won't apply metadata to the image files. And yet, the script is supposed to handle this case.
Reproduce the "bug" and comments
So select one image file + a text file as an example.
Actually, line 22
cmd.RunCommand("Select """&Filter&""" FILTER FILTERFLAGS=deselect")
works as intended, the text file is deselected.
Line 26, I check that the script registered this new state with
DOpus.Output "Number of selected files that the script will apply GPS : " & ClickData.Func.sourcetab.selected.count
It did since it only report the current number of selected images files. Only 1 in that case.
Line 98, just before applying the metadata, I check again that my variables are OK and the script still works with the selected file
DOpus.Output "Latitude = " & Lat & vbCrLf & "Longitude = " & Lon
DOpus.Output "Number of selected files that the script will apply GPS : " & ClickData.Func.sourcetab.selected.count
cmd.RunCommand("SetAttr META gpslatitude:"&Lat&"")
cmd.RunCommand("SetAttr META gpslongitude:"&Lon&"")
And yet, the metadata won't apply while if you only select image files from the very start, it works.
I'm lost. I really need some enlightenment.
Here is an updated version of the button used as reference for above. Unlike the original button, I just added the option to directly apply the GPS data from clipboard instead of using a prompt dialog as a step to retrieve them.
<?xml version="1.0"?>
<button backcol="none" display="both" textcol="none">
<label>Bouton</label>
<icon1>#newcommand</icon1>
<function type="script">
<instruction>@disablenosel</instruction>
<instruction>@filesonly</instruction>
<instruction />
<instruction>@script vbscript</instruction>
<instruction />
<instruction>' Please select a filter to exclude non images files</instruction>
<instruction>' Typacally it should be a filter that actually matches image files you want to apply coordinates to.</instruction>
<instruction>Dim Filter</instruction>
<instruction>Filter = "Non Image files"</instruction>
<instruction />
<instruction>Function OnClick(ByRef ClickData)</instruction>
<instruction> ' Clear the log output</instruction>
<instruction> DOpus.ClearOutput</instruction>
<instruction />
<instruction> ' INITIATE VARIABLES</instruction>
<instruction> UseDialog = False</instruction>
<instruction> Match = 0</instruction>
<instruction> Set cmd = ClickData.Func.command</instruction>
<instruction> Dim GpsInput</instruction>
<instruction />
<instruction> ' This will deselect all non image files</instruction>
<instruction> cmd.RunCommand("Select """&Filter&""" FILTER FILTERFLAGS=deselect")</instruction>
<instruction />
<instruction> ' Number of selected files to check the previous deselect command has run properly</instruction>
<instruction> ' And YES it is</instruction>
<instruction> CountSel = ClickData.Func.sourcetab.selected.count</instruction>
<instruction> DOpus.Output "Number of selected files that the script will apply GPS : " & CountSel</instruction>
<instruction />
<instruction> ' Check if at least 1 file is selected to continue else exit.</instruction>
<instruction> If ClickData.Func.sourcetab.selected_files.count < 1 Then</instruction>
<instruction> Set dlg = ClickData.Func.Dlg</instruction>
<instruction> dlg.Request "No file selected" & vbCrLf & "Please select at least 1 and run the command again", "OK"</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> ' Ask coordinates until they are valid</instruction>
<instruction> Do While Match = 0</instruction>
<instruction> ' In case prompt dialog is used</instruction>
<instruction> If UseDialog = True then</instruction>
<instruction> ' Create 1st Dialog object.</instruction>
<instruction> Set dlg = DOpus.Dlg</instruction>
<instruction> ' Initialise the object to display a message with 2 buttons and 1 input box</instruction>
<instruction> dlg.Window = DOpus.Listers(0)</instruction>
<instruction> dlg.title = "GPS coordinates"</instruction>
<instruction> dlg.message = "Paste the coordinates you copied from Google Maps."& vbCrLf & vbCrLf &"Ex: 47.338388, 0.990228"</instruction>
<instruction> dlg.buttons = "&OK|&Cancel"</instruction>
<instruction> dlg.icon = "question"</instruction>
<instruction> dlg.max = 128 ' enable the text field</instruction>
<instruction> ' Show the dialog and print the results to the script log</instruction>
<instruction> ret = dlg.Show</instruction>
<instruction> ' DOpus.Output "Dialog.Show returned " & ret</instruction>
<instruction> ' DOpus.Output "The string you entered was " & dlg.input</instruction>
<instruction />
<instruction> If ret = 0 then ' When user cancel action</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> GpsInput = dlg.input</instruction>
<instruction> ' DOpus.Output "GpsInput : """ & GpsInput & """"</instruction>
<instruction> Set dlg = Nothing ' destroy 1st dialog prompt</instruction>
<instruction> Else</instruction>
<instruction> ' In case prompt dialog is not used, just read the clipboard</instruction>
<instruction> If DOpus.GetClipFormat = "text" Then</instruction>
<instruction> GpsInput = DOpus.GetClip</instruction>
<instruction>' DOpus.Output "GpsInput : """ & GpsInput & """"</instruction>
<instruction> Else</instruction>
<instruction> Set dlg = ClickData.Func.Dlg</instruction>
<instruction> dlg.Request "Clipboard content is not as text format" & vbCrLf & "Be sure to copy only coordinates as text and try again", "OK"</instruction>
<instruction> Exit Function</instruction>
<instruction> End If</instruction>
<instruction />
<instruction> End if</instruction>
<instruction />
<instruction> ' Check if the input is a valid GPS coordinates</instruction>
<instruction> ' Create a RegExp object. See http://msdn2.microsoft.com/en-us/library/ms974570.aspx</instruction>
<instruction> Set re = New RegExp</instruction>
<instruction> re.IgnoreCase = True ' Case-sensitive matching.</instruction>
<instruction> re.Global = False ' All matches will be matched, not just the first match.</instruction>
<instruction />
<instruction> re.Pattern = "^(-?[1-8]?\d(?:\.\d{1,18})?|90(?:\.0{1,18})?),\s+?(-?(?:1[0-7]|[1-9])?\d(?:\.\d{1,18})?|180(?:\.0{1,18})?)$"</instruction>
<instruction> Set matches = re.Execute(GpsInput)</instruction>
<instruction> If matches.Count = 1 Then ' Case if pasted values contains valid coordinates</instruction>
<instruction> Match = 1</instruction>
<instruction>' DOpus.Output "GpsInput is VALID"</instruction>
<instruction>' DOpus.Output "Found " & matches.Count & " matches" & vbCRLF & "Match value : " & matches.Item(0).Value</instruction>
<instruction> Lat = matches.Item(0).SubMatches(0)</instruction>
<instruction> Lon = matches.Item(0).SubMatches(1)</instruction>
<instruction>' DOpus.Output "Latitude = " & Lat & vbCrLf & "Longitude = " & Lon</instruction>
<instruction> Else ' Case if pasted values contains invalid coordinates</instruction>
<instruction> Set dlg = ClickData.Func.Dlg</instruction>
<instruction> dlg.Request "The format of the coordinates you pasted are wrong" & vbCrLf & "Try again", "OK"</instruction>
<instruction> If UseDialog = False Then Exit Function</instruction>
<instruction> ' Clear the log output</instruction>
<instruction> DOpus.ClearOutput</instruction>
<instruction> End If</instruction>
<instruction> Loop</instruction>
<instruction />
<instruction> ' Apply coordinates to files</instruction>
<instruction> DOpus.Output "Latitude = " & Lat & vbCrLf & "Longitude = " & Lon</instruction>
<instruction> DOpus.Output "Number of selected files that the script will apply GPS : " & ClickData.Func.sourcetab.selected.count</instruction>
<instruction> cmd.RunCommand("SetAttr META gpslatitude:"&Lat&"")</instruction>
<instruction> cmd.RunCommand("SetAttr META gpslongitude:"&Lon&"")</instruction>
<instruction>End Function</instruction>
</function>
</button>
Regards