scripting contribution

Post Reply
wphx
Posts: 42
Joined: 19 Nov 08 10:14

scripting contribution

Post by wphx » 20 Feb 20 22:37

My work flow involves editing some jpeg & some raw. I make a shortlist of jpegs I want to focus on. I also want to be able to quickly select the corresponding raw files (where they exist) to put into a separate collection

Through working with online scripts in the repository (and marginal knowledge of pascal) I've created the script below. It currently is coded to recognise .rw2 files but can be adapted easily enough.

I've been fumbling around and it seems to work according my intention. I would like to be able to sort on photo date - that may come later unless someone can guide me on this.

There were a few odd things I couldn't get past (so created a new instance of ADs to delete idTempList at end of script)

I'm happy if anyone wants to tidy this up.

kind regards

anyhow:

Code: Select all

var
  i: Integer;
  RawFile: WideString;
  RawExt: WideString;
  ADs: TDBXOMClientDataSet;
  AGUID: String;
  AItems: TCatalogItems;
begin
  if Selected.Count = 0 then
  begin
    Say('No image selected');
    exit;
  end;

  AGUID :='wphFB798C977A734F4FACDF1FF204676A87';
  ADs := Catalog.NewDataSet;
  ADs.CommandText := 'delete from idTempList where ClassGUID=''' + AGUID + '''';
  ADs.Run;

  RawExt := '.rw2';

  for i := 0 to Selected.Count - 1 do
  begin
    If CompareText(ExtractFileExt(Selected.Items.FileName),RawExt)<>0 Then
    Begin
      RawFile := ChangeFileExt(Selected.Items.FileName,RawExt);
      If WideFileExists(RawFile) Then
      Begin
        ADs.CommandText := 'insert into idTempList (ClassGUID, GUID) ' +
                           'select ''' + AGUID + ''', idCatalogItem.GUID ' +
                           'from idCatalogItem inner join idFilePath ' +
                           'on idCatalogItem.PathGUID = idFilePath.GUID ' +
                           'where (idCatalogItem.FileName = ''' + ExtractFileName(RawFile) + ''') ' +
                           ' and (idFilePath.FilePath = ''' + ExtractFilePath(RawFile) + ''') ' +
                           '';
        //CopyTextToClipboard(ADs.CommandText);
        ADs.Run;
      end;
    end;
  end;

  ADs.CommandText := 'select ' + Catalog.FullColumnList('v.') + ' ' +
                     'from v_CatalogItem v, idTempList t ' +
                     'where t.ClassGUID = ''' + AGUID + ''' ' +
                     'and v.GUID = t.GUID ' +
                     'union all ' +
                     'select ' + Catalog.FullColumnList('v.') + ' ' +
                     'from v_CatalogItemVersion v, idTempList t ' +
                     'where t.ClassGUID = ''' + AGUID + ''' ' +
                     'and v.GUID = t.GUID ' +
                     'order by FullFileName ' +
                     '';
  //CopyTextToClipboard(ADs.CommandText);
  ADs.OpenSet;
  AItems := TCatalogItems.Create(TCatalogItem, '');
  AItems.Name := RawExt + ' from sel.';
  AItems.AddDataSet (ADs, True);
  PublicBroadCast(nil, 'OpenNewTab', nil);
  PublicBroadcastObject(nil, 'ShowImageResults', AItems, nil, nil);
  AItems.Free;
  ADs.CloseSet;
  Catalog.FreeDataSet (ADs);

  ADs := Catalog.NewDataSet;
  ADs.CommandText := 'delete from idTempList where ClassGUID=''' + AGUID + '''';
  ADs.Run;
  Catalog.FreeDataSet (ADs);
  Say ('Done. Found ' + RawExt + ' files are placed in a new Tab');
end;
Edit Hert; reformatted and placed in a code block

Hert
Posts: 6008
Joined: 13 Sep 03 7:24

Re: scripting contribution

Post by Hert » 21 Feb 20 11:43

Here's a cleaned up version.

Important is to use PublicCatalog and not Catalog (which was used in old scripts). The Catalog object variable is still available for backward compatibility only.
Another change was using the "Wide" versions like WideExtractFileName instead of ExtractFileName. The first will also work with special characters (like greek file names) where the latter would fail.

Furthermore I think your script is nice.

Code: Select all

const
  cGUID   = 'wphFB798C977A734F4FACDF1FF204676A87';
  cRawExt = '.rw2';
var
  i: Integer;
  RawFile: WideString;
  ADs: TDBXOMClientDataSet;
  AItems: TCatalogItems;
begin
  if Selected.Count = 0 then
  begin
    Say('No image selected');
    exit;
  end;

  ADs := PublicCatalog.NewDataSet;
  try
    ADs.CommandText := 'delete from idTempList where ClassGUID=''' + cGUID + '''';
    ADs.Run;
  finally
    PublicCatalog.FreeDataSet(ADs);
  end;

  for i := 0 to Selected.Count - 1 do
  begin
    if not WideSameText(WideExtractFileExt(Selected.Items[i].FileName), cRawExt) then
    begin
      RawFile := WideChangeFileExt(Selected.Items[i].FileName, cRawExt);
      if WideFileExists(RawFile) then
      Begin
        ADs := PublicCatalog.NewDataSet;
        try
          ADs.CommandText := 'insert into idTempList (ClassGUID, GUID) ' +
                             '  select ''' + cGUID + ''', idCatalogItem.GUID ' +
                             '  from   idCatalogItem ' +
                             '  inner  join idFilePath on idCatalogItem.PathGUID = idFilePath.GUID ' +
                             '  where  (idCatalogItem.FileName = ''' + WideExtractFileName(RawFile) + ''') ' +
                             '  and    (idFilePath.FilePath = ''' + WideExtractFilePath(RawFile) + ''') ' +
                             '';
          //CopyTextToClipboard(ADs.CommandText);
          ADs.Run;
        finally
          PublicCatalog.FreeDataSet(ADs);
        end;
      end;
    end;
  end;

  ADs := PublicCatalog.NewDataSet;
  try
    ADs.CommandText := 'select ' + PublicCatalog.FullColumnList('v.') + ' ' +
                       'from   v_CatalogItem v, idTempList t ' +
                       'where  t.ClassGUID = ''' + cGUID + ''' ' +
                       'and    v.GUID = t.GUID ' +
                       'union all ' +
                       'select ' + PublicCatalog.FullColumnList('v.') + ' ' +
                       'from   v_CatalogItemVersion v, idTempList t ' +
                       'where  t.ClassGUID = ''' + cGUID + ''' ' +
                       'and    v.GUID = t.GUID ' +
                       'order by FullFileName ' +
                       '';
    //CopyTextToClipboard(ADs.CommandText);
    ADs.OpenSet;
    AItems := TCatalogItems.Create(TCatalogItem, '');
    try
      AItems.Name := cRawExt + ' from sel.';
      AItems.AddDataSet (ADs, True);
      PublicBroadCast(nil, 'OpenNewTab', nil);
      PublicBroadcastObject(nil, 'ShowImageResults', AItems, nil, nil);
    finally
      AItems.Free;
    end;
    ADs.CloseSet;
  finally
    PublicCatalog.FreeDataSet (ADs);
  end;

  ADs := PublicCatalog.NewDataSet;
  try
    ADs.CommandText := 'delete from idTempList where ClassGUID=''' + cGUID + '''';
    ADs.Run;
  finally
    PublicCatalog.FreeDataSet (ADs);
  end;

  Say ('Done. Found ' + cRawExt + ' files are placed in a new Tab');
end;
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

wphx
Posts: 42
Joined: 19 Nov 08 10:14

Re: scripting contribution

Post by wphx » 21 Feb 20 12:50

Brilliant - the new code is absolutely clear - thanks - and your mod.s have helped me a lot.

wphx
Posts: 42
Joined: 19 Nov 08 10:14

Re: scripting contribution

Post by wphx » 21 Feb 20 13:23

oh ... the line 'widesametext(...' needs to read: 'not widesametext(...' - without the not it looks as though it works as it is picking up raw files in the selection, however it needs to pick up the *non* raw files in the selection and then test for existing raw files corresponding to the non raw file (for me at least - I always shoot jpg + raw when using raw).

Thanks again for the code revision

Hert
Posts: 6008
Joined: 13 Sep 03 7:24

Re: scripting contribution

Post by Hert » 21 Feb 20 15:06

I fixed the "not WideSameText" in my version above
This is a User-to-User forum which means that users post questions here for other users.
Feature requests, change suggestions, or bugs can be logged in the ticketing system

Post Reply