Resource

Resource Basics

Resource Name Migrate MediaPro / EM / iView Category to Label
Resource Version 1.0
Category Metadata
Downloads 941
Release Date 7/23/2020 11:07:15 AM
 

Resource Details

Description MediaPro still uses the long deprecated IPTC Annotation field "Category". As per the standards, Photo Supreme will convert this field by default as "photoshop:Category". However, MediaPro users typically use this field as a "Catalog Label" type of field.

This script will convert the Category field to a catalog label and place it in the top level "MediaPro Category" category.
Installation Instructions Download this script to your hard drive
Usage Instructions Then select the images you want to process and either:
1) Open script in scripter and select "Run," or
2) Set up batch with "Run Script."

After running the script the status will be available in the top level category called "MediaPro Category"
Changes in this version n.a.
Special Requirements Photo Supreme V4 or up
 

Author Information

Author Name IDimager Support
 

Script

{ Migrate EM / iView status to label
  Creates a label from the the XMP field photoshop:Category or IPTC-IIM field 15
  (deprecated Category)
  The new labels are written under the label category 'MediaPro Category' which has to
  be present in the Catalog Label hierarchy

  Author: IDimager
  Version history:
  v1.0 (2020-07-23)
}

function DetermineParentContainer: String;
var
  ACategory: TCatalogPropCategory;
  AProp: TCatalogItemProp;
begin
  result := '';
  // alternative 1; find a category by name that should contain the status structure
  ACategory := TCatalogPropCategory.Create(nil);
  try
    if not PublicCatalog.EnumCategoryNamed ('MediaPro Category', ACategory) then        // enable this line instead of the next on to find a category by name
    begin
      ACategory.GUID := NewGUID;
      ACategory.CategoryName := 'MediaPro Category';
      if not PublicCatalog.UpdateCategory(ACategory) then
        exit;
    end;
    result := ACategory.GUID;
  finally
    ACategory.Free;
  end;
end;

var
  APro: TxomProgress;
  i: Integer;
  AMain: TCatalogItem;
  ACatItem: TCatalogItem;
  AXmp: TXMP;
  AProp: TCatalogItemProp;
  AParam: TMacroParam;
  AParentGUID: String;
begin
  APro := TxomProgress.Create(nil);
  try
    APro.Cancel := False;
    APro.Max := Selected.Count;
    APro.Pos := 0;
    APro.Caption := 'Converting MediaPro Category';

    APro.Show;

    AParentGUID := DetermineParentContainer;
    if AParentGUID = '' then
    begin
      Say('Parent category not found or couldn''t be created.');
      exit;
    end;

    AMain := TCatalogItem.Create(nil);
    ACatItem := TCatalogItem.Create (nil);
    AXmp := TXMP.Create (nil);
    try
      for i := 0 to Selected.Count - 1 do
      begin
        //Say('Setting progress');
        APro.Pos := i + 1;
        APro.ProgressText := Selected.Items[i].FileNameOnly;

        // find the image item in the catalog (and only process found items
        if PublicCatalog.FindImageCombined (Selected.Items[i], ACatItem, true, vptNone) then
        begin
          PublicCatalog.LoadXMPForItem (ACatItem, AXmp, Options.CachedXMP);

          // find the Event info
          AParam := AXmp.FindDesignProperty ('http://ns.adobe.com/photoshop/1.0/', 'photoshop:Category');
          if AParam = nil then
          begin
            // try converting Exif to XMP which will map IPTC-IIM::15 to photoshop:Category
            AXmp.InitializeFromTifFile(ACatItem.ExifFileName, True, True, True);
            // and find again
            AParam := AXmp.FindDesignProperty ('http://ns.adobe.com/photoshop/1.0/', 'photoshop:Category');
          end;
          if AParam <> nil then
          begin
            if AParam.Content <> '' then
            begin
              AProp := TCatalogItemProp.Create(nil);
              try
                // is there an existing label with this name?
                if not PublicCatalog.EnumPropName(AParentGUID, AParam.Content, AProp, false) then
                begin
                  // not available yet, so create one
                  AProp.GUID         := NewGUID;                    // generate a new GUID
                  AProp.PropName     := AParam.Content;
                  PublicCatalog.StorePropToDatabase (AProp, AParentGUID, False);
                end;

                // Assign the label to the catalog item
                PublicCatalog.AddPropToItem (ACatItem, AProp, False, False);
              finally
                AProp.Free;
              end;
            end;
          end;
        end;
      end;
    finally
      AXmp.Free;
      ACatItem.Free;
      AMain.Free;
    end;

    APro.Hide;

    if APro.Cancel then
      Say ('Cancelled');
  finally
    APro.Free;
  end;
end;