Resource

Resource Basics

Resource Name Import from sidecar XMP file
Resource Version 1.01
Category Metadata
Downloads 3082
Release Date 1/25/2018 10:29:18 AM
 

Resource Details

Description This script will search for XMP sidecar files for a selection of images.

For every file that has a XMP sidecar file (even for files that typically have embedded metadata like JPG, TIF or DNG), the XMP will be imported completely to the catalog and replace the existing metadata there.

Use with caution.
Installation Instructions 1. Download the script to your local hard drive
Usage Instructions 1. Select one or more thumbnails
2. Start the Scripter (Tools->Scripter)
3. Load the downloaded script
4. Run the script
Changes in this version 1.01; Fix for progress being off
Special Requirements
 

Author Information

Author Name IDimager Support
 

Script


  procedure ImportXMPSidecarFor(AImage: TImageItem);
  var
    AXmp: TXMP;
    ASidecar: WideString;
  begin
    ASidecar := WideChangeFileExt(AImage.FileName, '.xmp');

    AXmp := TXMP.Create(False);
    AXmp.LoadFromFile(ASidecar);
    PublicCatalog.SaveXMPForImage(AImage, AXmp, PublicOptions.CachedXMP);
    PublicCatalog.ReadXMPForImageAdvanced(AImage, PublicOptions.XMPSyncReadSettings, AXmp);
    AXmp.Free;
  end;

var
  i: Integer;
  AList: TStringList;
  AImage: TImageItem;
  ASidecar: WideString;
  APro: TxomProgress;
begin
  if Selected.Count = 0 then
  begin
    Say2('No images selected.', 'Select one or more thumbnails and try again.');
    exit;
  end;

  AList := TStringList.Create;

  APro := TxomProgress.Create(nil);
  APro.Caption := 'Finding files with sidecar XMP file';
  APro.Max := Selected.Count;
  APro.Pos := 0;
  for i := 0 to Selected.Count - 1 do
  begin
    AImage := Selected.Items[i];

    APro.Pos := i + 1;
    APro.ProgressText := AImage.FileNameOnly;
    if APro.Cancel then break;

    ASidecar := WideChangeFileExt(AImage.FileName, '.xmp');
    if WideFileExists(ASidecar) then
      AList.AddObject(AImage.FileName, AImage);
  end;
  APro.Free;

  if AList.Count > 0 then
  begin
    if AskYN('There are ' + IntToStr(AList.Count) + ' images found in your selection that have XMP sidecar files.' + CrLf2 +
             'Do you want to import from those XMP files to your catalog?' + CrLf2 +
             'WARNING: the metadata from the XMP sidecar file will replace the currently existing metadata and use your sync-read settings to process the XMP.')
    then
    begin
      APro := TxomProgress.Create(nil);
      APro.Caption := 'Import metadata from sidecar XMP file';
      APro.Max := AList.Count;
      APro.Pos := 0;
      for i := 0 to AList.Count - 1 do
      begin
        AImage := AList.Objects[i];

        APro.Pos := i + 1;
        APro.ProgressText := AImage.FileNameOnly;
        if APro.Cancel then break;

        ImportXMPSidecarFor(AImage);
      end;
      APro.Free;
    end;
  end
  else
    Say('None of the selected files have a XMP sidecar file');

  AList.Free;
end;