Resource

Resource Basics

Resource Name Migrate MediaPro / EM / iView Event to Label
Resource Version 1.4.5
Category Metadata
Downloads 1091
Release Date 2/3/2016 11:40:07 PM
 

Resource Details

Description Converts EM / iView event to a Photo Supreme Event Catalog label
Installation Instructions Copy the script somewhere
Usage Instructions Select a set of photos and then either:
1) Load the script into the scripter and click run, or
2) Set up a batch process with "Run Script"
Changes in this version 1.0 13/12/2009
- Initial release
1.1 13/03/2010 - Dirk Schiphorst
- first checks EM fields and then iView
1.2 Hert van Zwietering
- Updated for Photo Supreme
1.3 Hert van Zwietering
- The script now uses PublicCatalog
1.4 4 aug 2020 - Hert van Zwietering
- Dedicated progress box and file name only progress text
1.4 5 sep 2021 - Hert van Zwietering
- Added support for reading FixtureID from IPTC as the Event if the event is not in the XMP metadata
Special Requirements
 

Author Information

Author Name Andrew Certain
 

Script

{ Migrate EM / iView event to label
  Creates a label from the the XMP field expressionmedia:event or mediapro:event
  The new labels are written under the label category 'Events' which has to
  be present in the Catalog Label hierarchy

  $Id: Migrate EM-iView Event to Label.psc 244 2010-03-13 11:49:18Z dirk $

  Author: Dirk Schiphorst
  Version history:
  1.0 13/12/2009
      - Initial release
  1.1 13/03/2010 - Dirk Schiphorst
      - first checks EM fields and then iView
  1.2 IDimager
      - Updated for Photo Supreme
  1.3 IDimager
      - The script now uses PublicCatalog  
  1.4 4 aug 2020 - IDimager
      - Dedicated progress box and file name only progress text
  1.4 5 sep 2021 - IDimager
      - Added support for reading FixtureID from IPTC as the Event if the event is not in the XMP metadata
}

var
  i: Integer;
  AParentGUID: String;
  AHit: Integer;

function DetermineParentContainer: String;
var
  ACategory: TCatalogPropCategory;
  AProp: TCatalogItemProp;

begin
  result := Catalog.Events.GUID;

  // alternative 1; find a category by name that should contain the places structure
  {
  ACategory := TCatalogPropCategory.Create (nil);
  if Catalog.EnumCategoryNamed ('Events', ACategory) then        // enable this line instead of the next on to find a category by name
    result := ACategory.GUID;
  ACategory.Free;
  }
  // alternative 2; find a catalog label by name that should contain the places structure
  {
  AProp := TCatalogItemProp.Create (nil);
  if Catalog.FindPropByName ('My Events', AProp, '', True) then        // enable this line instead of the next on to find a category by name
    result := AProp.GUID;
  AProp.Free;
  }
end;

function ReadEventValueForItem(AItem: TImageItem; AXmp: TXMP): WideString;
var
  AParam: TMacroParam;
  i: Integer;
  ATif: TTif;
  ATag: TTifTag;
begin
  result := '';

  // find the Event info
  AParam := AXmp.FindDesignProperty ('http://ns.microsoft.com/expressionmedia/1.0/', 'expressionmedia:Event');
  if AParam = nil then
    AParam := AXmp.FindDesignProperty ('http://ns.iview-multimedia.com/mediapro/1.0/', 'mediapro:Event');
  if AParam <> nil then
    result := Nvl(AParam.Content, '');
  else
  begin
    // check FixtureID in IPTC. Old iView wrote Event as IPTC's FixtureID
    ATif := TTif.Create (nil);
    try
      ATif.FileName := AItem.ExifFileName;
      ATif.Load (True, False);

      // check FixtureID in IPTC
      for i := ATif.IPTCIFD.Tags.Count - 1 downto 0 do
      begin
        ATag := ATif.IPTCIFD.Tags.Items[i];
        if ATag.TagNumber = 22 then        // FixtureID
        begin
          result := ATag.TagValue;
          exit;
        end;
      end;
    finally
      ATif.Free;
    end;
  end;

end;

procedure HandleItem (AItem: TImageItem; ACatItem: TCatalogItem; AXmp: TXMP; AProp: TCatalogItemProp);
var
  AEventVal: WideString;
begin
  // find the image item in the catalog (and only process found items
  if PublicCatalog.FindImageCombined (AItem, ACatItem, true, vptNone) then
  begin
    PublicCatalog.LoadXMPForItem (ACatItem, AXmp, Options.CachedXMP);

    // get the Event value
    AEventVal := ReadEventValueForItem(AItem, AXmp);
    if AEventVal <> '' then
    begin
      // is there an existing label with this name?
      if not Catalog.EnumPropName(AParentGUID, AEventVal, AProp, false) then
      begin
        // not available yet, so create one
        AProp.GUID         := NewGUID;                    // generate a new GUID
        AProp.PropName     := AEventVal;
        PublicCatalog.StorePropToDatabase (AProp, AParentGUID, False);
      end;

      // Assign the label to the catalog item
      PublicCatalog.AddPropToItem (ACatItem, AProp, False, False);
      AHit := AHit + 1;
    end;
  end;
end;

var
  AProgress: TxomProgress;
begin
  if Selected.Count = 0 then
  begin
    Say('No images selected');
    exit;
  end;

  AParentGUID := DetermineParentContainer;
  if AParentGUID = '' then
  begin
    Say('Parent label not found');
    exit;
  end;

  AHit := 0;

  AProgress := TxomProgress.Create(nil);
  try
    AProgress.Cancel := False;
    AProgress.Caption := 'Migrate EM-iView Event';
    AProgress.Max := Selected.Count;
    AProgress.Pos := 0;
    AProgress.Show;

    ACatItem := TCatalogItem.Create (nil);
    AXmp := TXMP.Create (nil);
    AProp := TCatalogItemProp.Create(nil);
    try
      for i := 0 to Selected.Count - 1 do
      begin
        AProgress.Pos := i + 1;
        AProgress.ProgressText := Selected.Items[i].FileNameOnly;

        HandleItem (Selected.Items[i], ACatItem, AXmp, AProp);
        if AProgress.Cancel then
          break;
      end;
      AProgress.Hide;
    finally
      AProp.Free;
      AXmp.Free;
      ACatItem.Free;
    end;

    if AProgress.Cancel then
      Say ('Operation cancelled.');
  finally
    AProgress.Free;
  end;
end;