{ Description: This script will migrate the existing catalog sets array as written by iView to A dedicated iView/EM Portfolio Original Author: Dirk Schiphorst/Andrew Certain Version history: 1.04; 4 Aug 2020; Hert van Zwietering Now uses a dedicated progress component; and only file name in the progress text 1.01; Removed dialog that appeared for every image 1.02; Added support for sub catalog sets 1.03; The script no longer removes the tags from metadata in the file 1.00; 03 Sep 2018; Hert van Zwietering Initial release. Based on iView Contacts to People script by Andrew Certain } const cPortfolioGUID = '4A92087C31A4443C82A1089E82829525'; cGalleryGUID = '0A52C02AA7A642E0BFDC1CEE3B3C9058'; cUpdateTags = 0; // set to 1 to update metadata and have the EM/iView tags removed procedure CheckPortfolio; var APortfolio: TImageModel; AGall: TImageGallery; begin APortfolio := TImageModel.Create(nil); if not PublicCatalog.EnumModel(cPortfolioGUID, APortfolio) then begin APortfolio.GUID := cPortfolioGUID; APortfolio.ModelName := 'MediaPro/EM/iView'; APortfolio.Galleries.Clear; AGall := APortfolio.Galleries.Add as TImageGallery; AGall.GUID := cGalleryGUID; AGall.GalleryName := APortfolio.ModelName; AGall.Collections.Clear; PublicCatalog.StoreModelToDatabase(APortfolio); end; APortfolio.Free; end; procedure Process_iView (ACatItem: TCatalogItem; var ATif: TTif; var AXmp: TXMP); var i, j, k: Integer; ATag: TTifTag; AIVSets: TMacroParam; AEntry: WideString; AList, ASl, ACollList: TTntStringList; AParentColls, AColls: TImageCollections; AColl: TImageCollection; AParentGUID: String; begin AList := TTntStringList.Create; for i := ATif.IPTCIFD.Tags.Count - 1 downto 0 do begin ATag := ATif.IPTCIFD.Tags.Items[i]; if ATag.TagNumber = 255 then // iView/EM Sets begin if Trim(ATag.TagValue) = '' then // skip empty contacts continue; ASl := TTntStringList.Create; ASl.CommaText := ATag.TagValue; // the tag is comma separated by IDI for j := 0 to ASl.Count - 1 do begin if Trim(ASl.Strings[j]) = '' then continue; if AList.IndexOf (ASl.Strings[j]) = -1 then // prevent dups AList.Add(ASl.Strings[j]); end; ASl.Free; ATag.Free; end; end; // the list now contains all catalog sets from IPTC, now add the XMP Catalog Sets from the EM - iView schema (if available) AIVSets := AXmp.FindDesignProperty ('http://ns.microsoft.com/expressionmedia/1.0/', 'expressionmedia:CatalogSets'); if AIVSets = nil then AIVSets := AXmp.FindDesignProperty ('http://ns.iview-multimedia.com/mediapro/1.0/', 'mediapro:CatalogSets'); if AIVSets <> nil then begin // found, now process all items in the iView Catalog Sets array (it's an "XMP Bag" datatype) for i := 0 to AIVSets.ArrayContent.Count - 1 do begin if Trim(Nvl(AIVSets.ArrayContent.Items[i].Content, '')) = '' then continue; if AList.IndexOf (AIVSets.ArrayContent.Items[i].Content) = -1 then // prevent dups AList.Add (AIVSets.ArrayContent.Items[i].Content); end; AIVSets.Free; end; // make sure the portfolio exists CheckPortfolio; AColls := TImageCollections.Create(TImageCollection, ''); PublicCatalog.EnumCollectionsForParent(cGalleryGUID, AColls); for i := 0 to AColls.Count - 1 do PublicCatalog.RemoveItemFromCollection(ACatItem, AColls.Items[i]); for i := 0 to AList.Count - 1 do begin ACollList := TTntStringList.Create; Tokenize(AList.Strings[i], '|', ACollList); AParentGUID := cGalleryGUID; AParentColls := AColls; for j := 0 to ACollList.Count - 1 do begin AEntry := ACollList.Strings[j]; AColl := AParentColls.FindNamed(AEntry) if AColl = nil then begin // create collection AColl := AParentColls.Add as TImageCollection; AColl.CollectionName := AEntry; PublicCatalog.StoreCollectionToParent(cGalleryGUID, AParentGUID, AColl); end; // add image to the lowest leaf collection if j = ACollList.Count - 1 then PublicCatalog.StoreItemToCollection(ACatItem, AColl, PublicOptions.XMPSyncReadSettings, False); AParentColls := AColl.SubFolders; AParentGUID := AColl.GUID; AParentColls.Clear; PublicCatalog.EnumCollectionsForParent(AParentGUID, AParentColls); for k := 0 to AParentColls.Count - 1 do PublicCatalog.RemoveItemFromCollection(ACatItem, AParentColls.Items[k]); end; ACollList.Free; end; AColls.Free; AList.Free; end; var ATif: TTif; AXmp: TXMP; AItem: TImageItem; i: Integer; ACatItem: TCatalogItem; AProgress: TxomProgress; begin if Selected.Count = 0 then begin Say ('No images selected'); exit; end; if not Ask ('This script will migrate CatalogSets entries as written with EM/iView to Portfolios. The original CatalogSets found (if any) will be permanently moved.' + CrLf2 + 'Are you sure you want to continue?') then exit; AProgress := TxomProgress.Create(nil); try AProgress.Cancel := False; AProgress.Caption := 'Migrate EM-iView Catalog Sets'; AProgress.ProgressBar := True; AProgress.Max := Selected.Count; AProgress.Show; AXmp := TXmp.Create (True); ATif := TTif.Create (nil); ACatItem := TCatalogItem.Create (nil); try //ATif.UseCache := False; for i := 0 to Selected.Count - 1 do begin AProgress.ProgressText := Selected.Items[i].FileNameOnly; AProgress.Pos := i + 1; if AProgress.Cancel then break; ATif.Reset; AXmp.Reset; ATif.FileName := Selected.Items[i].ExifFileName; ATif.Load (True, False); // now update the XMP if not PublicCatalog.FindImageCombined (Selected.Items[i], ACatItem, False, phtNone) then if not PublicCatalog.AddFile (Selected.Items[i], AcatItem, False) then Continue; PublicCatalog.LoadXMPForItem (ACatItem, AXmp, Options.CachedXMP); AXmp.InitializeFromTif (ATif, True, True, True, False, txusAll); Process_iView (ACatItem, ATif, AXmp); if cUpdateTags <> 0 then ATif.UpdateTags; PublicCatalog.SaveXMPForItem (ACatItem, AXmp, Options.CachedXMP); end; finally AXmp.Free; ACatItem.Free; end; AProgress.Hide; if AProgress.Cancel then Say ('Cancelled') else SendVisualFeedback('Finished migrating iView/EM/MediaPro catalog sets to portfolio collections for ' + IntToStr(Selected.Count) + ' images', 5000); finally AProgress.Free; end; end;