Resource

Resource Basics

Resource Name Gather Matching RAW files
Resource Version 1
Category Search Scripts
Downloads 671
Release Date 7/20/2020 10:20:58 AM
 

Resource Details

Description This script analyzes a set of selected images and locates the raw file corresponding to the image. (e.g. select a group of .jpg images, xxxx.jpg - returns xxxx.raw if xxxx.raw exists). Raw files found are displayed in a new tab. NB: If raw files are included in the selection which do not correspond to an image (e.g. a .jpg) it will *not* be included in the return set.
Installation Instructions Download into a folder. Run from the scripter tool in PSU
Usage Instructions 1. Use any PSU method to select a group of images.
2. Run this script
3. You will be asked for the raw extension you are looking for (without the '.'in the extension)
4. Results are displayed in a new tab
5. If you have want to change the default raw file extension, modify the constant cRawExt
Changes in this version added dialog box to query the raw extension name
Special Requirements
 

Author Information

Author Name W. Heidrich (with help from Hert)
 

Script

// script to locate raw files corresponding to selected images
// NB: this script does not return raw files which are already in the selection

const
  cGUID   = 'wphFB798C977A734F4FACDF1FF204676A87';
  cRawExt = 'rw2';   // default extension - change this to suit your practice
var
  ATextBox: TvxTextBox;  // response from form with extension
  AForm: TvxSceneForm;   // extension form
  RawExt: WideString;    // extension to work with


// get extension of raw file  from form
 function CreateForm: TvxSceneForm;
  var
    ARoot: TvxVisualObject;
    ALabel: TvxLabel;
  begin
    result := TvxSceneForm.Create(nil);
    result.Caption := UTF8Encode('File extension for RAW file');
    result.Position := poScreenCenter;
    result.Height := 100 * result.DPIFactor;

    ARoot := result.Root;

    ALabel := TvxLabel.Create(ARoot);
    ALabel.Text := 'Enter RAW file extension: (default: '+cRawExt+')';
    ALabel.TextAlign := vgTextAlignNear;
    ALabel.Padding.Left := 10;
    ALabel.Padding.Top := 10;
    ALabel.Align := vaTop;
    ARoot.AddObject(ALabel);

    ATextBox := TvxTextBox.Create(ARoot)
    ATextBox.Padding.Left := 10;
    ATextBox.Padding.Right := 10;
    ATextBox.Padding.Top := 10;
    ATextBox.Align := vaTop;
    ARoot.AddObject(ATextBox);

  end;

// finds raw files with extension specified in selected images
procedure FindRaw(RawExt: WideString); // rawext - format '.zzz'  where zzz is the raw extension name
var
  i: Integer;
  ADs: TDBXOMClientDataSet;
  AItems: TCatalogItems;
  RawFile: WideString;

begin
  ADs := PublicCatalog.NewDataSet;
  try
    ADs.CommandText := 'delete from idTempList where ClassGUID=''' + cGUID + ''''; // empty the results list
    ADs.Run;
  finally
    PublicCatalog.FreeDataSet(ADs);
  end;

  for i := 0 to Selected.Count - 1 do  // for each selected image
  begin
    if not WideSameText(WideExtractFileExt(Selected.Items[i].FileName), RawExt) then  // check extension to match raw extension
    begin
      RawFile := WideChangeFileExt(Selected.Items[i].FileName, RawExt); // if this isn't already a raw file, create a raw filename which corresponds to the selected image
      if WideFileExists(RawFile) then  // ifg it exists, add it to the data set
      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;  // create the resultant dataset for display
  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, '');  // results
    try  // display results in new tab
      AItems.Name := RawExt + ' 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  // clean up templist - remove my results from the list
    ADs.CommandText := 'delete from idTempList where ClassGUID=''' + cGUID + '''';
    ADs.Run;
  finally
    PublicCatalog.FreeDataSet (ADs);
  end;

  Say ('Done. Found ' + RawExt + ' files are placed in a new Tab');
end;

// ----  main - get extension of raw file and fire up search ---
begin
  if Selected.Count = 0 then
  begin
    Say('No image selected');
    exit;
  end;

  AForm := CreateForm;  // dialog box for raw extension
  try
    ATextBox.Text := cRawExt; // default raw extension
    AForm.PrepareModal([mbOK, mbCancel]);
    AForm.ShowModal;
    if AForm.ModalResult = mrOk then
    begin
      if Length(ATextBox.Text) <> 0 then // double check for blank extension entered
      begin
         RawExt := '.'+ ATextBox.Text;  // create the full extension including the '.'at the front
         FindRaw(RawExt); // go look
      end;
    end;
  finally
    AForm.Free;
  end;
end;