Resource

Resource Basics

Resource Name Assign Comma Separated Labels
Resource Version 1.1
Category Catalog
Downloads 1232
Release Date 6/10/2017 1:50:55 PM
 

Resource Details

Description This script allows you to enter a comma separated list of Catalog Labels, which will then be created and applied to the selected images in the Collection Viewer
Installation Instructions Download the script to your hard drive
Usage Instructions 1. Select one or more images
2. Select Tools->Scripter
3. Load this script
4. Run the script by clicking the run button (F9)
5. Enter (or right click and paste) the comma separated list
Changes in this version n.a.
Special Requirements
 

Author Information

Author Name IDimager Support
 

Script

var
  ACatItem: TCatalogItem;
  i: Integer;
  ACommaText: WideString;
  ATokens: TTntStringList;
  AToken: WideString;
  AProps: TCatalogItemProps;
  AProp: TCatalogItemProp;
  AItems: TCatalogItems;
begin
  if Selected.Count = 0 then
    Say('No image selected in the Collection Viewer')
  else
  begin
    ACommaText := '';
    if not AskInput('Title', 'Comma list', 'enter a comma separated list of names to assign as catalog labels', ACommaText, False, nil) then
      exit;

    ATokens := TTntStringList.Create;
    AProps := TCatalogItemProps.Create(TCatalogItemProp, '');
    AItems := TCatalogItems.Create(TCatalogItem, '');

    Tokenize(ACommaText, ',', ATokens);
    for i := 0 to ATokens.Count - 1 do
    begin
      AToken := Trim(ATokens.Strings[i]);
      AProp := TCatalogItemProp.Create(nil);
      if not PublicCatalog.FindPropByName(AToken, AProp, '', True) then
      begin
        // store it now
        AProp.PropName := AToken;
        PublicCatalog.StorePropToDatabase(AProp, Catalog.KeywordsGUID, False);
      end;
      AProp.CopyTo(AProps, False);
      AProp.Free;
    end;

    for i := 0 to Selected.Count - 1 do
    begin
      ACatItem := TCatalogItem.Create(nil);

      if PublicCatalog.FindImageCombined(Selected.Items[i], ACatItem, 0, True) then
      begin
        ACatItem.CopyTo(AItems, False);
      end;

      ACatItem.Free;
    end;

    if Ask('Are you sure you want to assign ' + IntToStr(AProps.Count) + ' catalog label(s) ' + CrLf2 + AProps.PropList(CrLf) + CrLf2 + 'to ' + IntToStr(AItems.Count) + ' image(s)?') then
    begin
      PublicCatalog.StoreItemsToTempList(AItems, False);
      PublicCatalog.AddPropsToItemsInTempList(AItems, AProps);
      PublicCatalog.RemoveItemsFromTempList(AItems);
    end;

    AItems.Free;
    AProps.Free;
    ATokens.Free;

  end;
end;