Resource

Resource Basics

Resource Name Migrate MediaPro / EM / iView Status to Label
Resource Version 1.2
Category Metadata
Downloads 1052
Release Date 2/3/2016 11:45:22 PM
 

Resource Details

Description Copies the Expression Media "Status" field to a new Catalog Label.
Installation Instructions Copy script somewhere
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 Status"
Changes in this version 1.1 update to better support Photo Supreme

1.2 The top level category will be created if it doesn't exist up front

1.21 Added dedicated progress bar
Special Requirements
 

Author Information

Author Name Andrew Certain
 

Script

{ Migrate EM / iView status to label
  Creates a label from the the XMP field expressionmedia:Status or mediapro:Status
  The new labels are written under the label category 'MediaPro Status'

  Author: Andrew Certain
  Version history:
  1.0 2016-01-24 by Andrew Certain
      - initial version

  Author: 
  1.2 2020-07-23 by IDimager
    - The category will be created if it doesn't exist yet
  1.21 2020-08-04 by IDimager
    - Added dedicated progress bar

}

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

begin
//  result := PublicCatalog.Events.GUID;

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

var
  i: Integer;
  AMain: TCatalogItem;
  ACatItem: TCatalogItem;
  AXmp: TXMP;
  AProp: TCatalogItemProp;
  AParam: TMacroParam;
  AParentGUID: String;
  AProgress: TxomProgress;
begin
  AProgress := TxomProgress.Create(nil);
  try
    AProgress.Cancel := False;
    AProgress.Caption := 'Copy Media Pro Status To Tag';
    AProgress.Max := Selected.Count;
    AProgress.Pos := 0;

    AProgress.Show;

    AParentGUID := DetermineParentContainer;
    if AParentGUID = '' then
    begin
      Say('Parent category not found or could not 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
        AProgress.Pos := i + 1;
        AProgress.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
          //Say('Found image');
          PublicCatalog.LoadXMPForItem (ACatItem, AXmp, Options.CachedXMP);

          // find the Event info
          AParam := AXmp.FindDesignProperty ('http://ns.microsoft.com/expressionmedia/1.0/', 'expressionmedia:Status');
          if AParam = nil then
            //Say('Looking again');
            AParam := AXmp.FindDesignProperty ('http://ns.iview-multimedia.com/mediapro/1.0/', 'mediapro:Status');
          if AParam <> nil then
          begin
            //Say('Found something');
            if AParam.Content <> '' then
            begin
              AProp := TCatalogItemProp.Create(nil);
              try
                //Say('Found property: ' + AParam.Content);
                // 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;

    AProgress.Hide;

    if AProgress.Cancel then
      Say ('Cancelled')
    else
      Say ('Status is converted to catalog labels in the MediaPro Status top level Category');
  finally
    AProgress.Free;
  end;
end;