Pascal Script

  • 26 May

    Image and sidecar xml workflow question

    Q: We have a new process that backs up and then moves an image file and sidecar xml file into an input directory [folder A] for our automated photo toning software.
    The xml file contains instructions for cropping and has the same name as the image file with the exception of their file extensions, for example 230519_511627666.xml and 230519_511627666.jpg.
    The photo toning software ingests both the .xml and .jpg and attempts to tone the image, but if the .jpg fails it is output to an error folder [B] without being cropped and toned.
    We pick up the errored .jpg from folder B, resize it with other software and drop it to another folder [C].
    We need to then move the .jpg from folder C back to input folder A to try it again, but it requires its corresponding .xml file which can be found in the backup folder [D] be dropped alongside it again to process and tone.
    Is it possible with a Limagito rule to monitor source folder C and if an image file is found, grab the .xml file of the same name from folder D, then drop them both to folder A?
    Hope that makes sense! Thanks, David

    A: Yes, should be possible. We’ll prepare a script for this asap.

    • We created the following directory structure for the test of the script:

    Image and sidecar xml

    • Source is the C folder (resized files):

    Limagito file mover windows as source

    • Filename Include Filter, we only want to scan for jpg files:

    limagito file mover filename include filter

    • Enable and add ‘On Destination’ Pascal Script:

    limagito file mover pascal script

    • Don’t forget to adjust the Path const values:
    var
      tmpFilename: String;
    Const
      // Path must end with a \
      ctBackupPath = 'C:\Test\AJC\D\';
      ctDestinationPath = 'C:\Test\AJC\A\';
    Begin
      psExitCode:= 0;
      tmpFilename := ChangeFileExt(psFileName, '.xml');
      If FileExists(ctBackupPath + tmpFilename) Then
      Begin
        If psCopyFile(ctBackupPath + tmpFilename, ctDestinationPath + tmpFilename, False) Then
        Begin
           psExitCode:= 1;
           psLogWrite(1, '', 'Copy file success of ' + ctBackupPath + tmpFilename + ' to ' + ctDestinationPath + tmpFilename);
        End
        Else
        Begin
          psLogWrite(1, '', 'Copy file error of ' + ctBackupPath + tmpFilename + ' to ' + ctDestinationPath + tmpFilename);
        End;
      End
      Else
        psLogWrite(1, '', 'Error, xml file does not exist: ' + ctBackupPath + tmpFilename);
    End.

    limagito file mover pascal script as destination

    Feedback user:

    • Thank you, I’ll try this out and let you know if I have any issues with it. Appreciate the quick response!
    • Just wanted to update, this rule and script appears to work great and I have it in place in our production workflow now, thanks again!

    #filetransfer #mft #filemanagement

    If you need any info  about this ‘Image and sidecar xml workflow question’, please let us know.

    Best regards,

    Limagito Team

     

    By Limagito-Team Image Pascal Script , ,
  • 14 May

    New counters added in Limagito File Mover

    Newly added in Limagito File Mover recently:

    Values total counters (history):

    • psTotalFiles Counter:  %CSC
    • psTotalFilesSrcError Counter:  %CFS
    • psTotalFileDstError Counter:  %CFD
    • psTotalControlSrc Counter:  %CCS
    • psTotalControlDst Counter:  %CCD

    The following counters will reset themself On Rule Begin:

    • psCurrentsFiles Counter:  %ZSC
    • psCurrentFilesSrcError Counter:  %ZFS
    • psCurrentFilesDstError Counter:  %ZFD
    • psCurrentControlSrcError Counter:  %ZCS
    • psCurrentControlDstError Counter:  %ZCD

    limagito file mover counter parameters

    These can be used for example in email events.

    New counters added and used in email events

     

    Result of sent email:

    New counters added in email example

    These counters are also available as Pascal Script var so this means you can control only to send an error email if for example the value of an error counter reaches a certain value.

    limagito file mover on error event

    Important, enable ‘Use Pascal Script as Event Precondition’ in the options tab:

    use pascal script as precondition in limagito file mover

    You can create any combination of our counters to determine when the error event should actually be sent. Please let us know if you need any help here.

    limagito file mover pascal script as precondition using counters

    An example of the the new counters being used in our Pascal Script ‘On Rule End’ option:

    New counters added in our file mover pascal script option

    RunTime Log Result:

    New counters added in our file mover pascal script option

    #filetransfer #mft #filemanagement

    If you need any info  please let us know.

    Best regards,

    Limagito Team

    By Limagito-Team How-to Pascal Script
  • 07 May

    Copy only the modified contents of a file

    Q: We are using Limagito for different projects and we have a query to its functionality. We want to see that it can copy only the modified contents of a file  in a new file with same name. Below is an example on what is being appended and how.

    Let us use the following example: Equipment_AE_Alarm_Event0_2023-05-04_00.00.01.csv.

    • The original content of this csv file:

    “Time;””AlarTxt””;””AlmPrio””;””Almusr””;””acksts”””
    “2023-05-03 00:00:02;””sample text1″”;200;KLMN;1″
    “2023-05-03 00:00:03;””sample text2″”;300;KLMN;1″
    “2023-05-03 00:00:04;””sample text3″”;100;KLMN;0″
    “2023-05-03 00:00:05;””sample text4″”;200;KLMN;1″
    “2023-05-03 00:00:06;””sample text5″”;200;KLMN;1″

    • Expected content of the output file would be the same when we scan this file for the first time:

    “Time;””AlarTxt””;””AlmPrio””;””Almusr””;””acksts”””
    “2023-05-03 00:00:02;””sample text1″”;200;KLMN;1″
    “2023-05-03 00:00:03;””sample text2″”;300;KLMN;1″
    “2023-05-03 00:00:04;””sample text3″”;100;KLMN;0″
    “2023-05-03 00:00:05;””sample text4″”;200;KLMN;1″
    “2023-05-03 00:00:06;””sample text5″”;200;KLMN;1″

    • Data is being added to this csv so the content of file during the next scan is showing more entries:

    “Time;””AlarTxt””;””AlmPrio””;””Almusr””;””acksts”””
    “2023-05-03 00:00:02;””sample text1″”;200;KLMN;1″
    “2023-05-03 00:00:03;””sample text2″”;300;KLMN;1″
    “2023-05-03 00:00:04;””sample text3″”;100;KLMN;0″
    “2023-05-03 00:00:05;””sample text4″”;200;KLMN;1″
    “2023-05-03 00:00:06;””sample text5″”;200;KLMN;1″
    “2023-05-03 00:00:06;””sample text6″”;200;KLMN;0″
    “2023-05-03 00:00:06;””sample text7″”;200;KLMN;1″
    “2023-05-03 00:00:08;””sample text8″”;200;KLMN;0″
    “2023-05-03 00:00:10;””sample text9″”;200;KLMN;1″
    “2023-05-03 00:00:12;””sample text10″”;200;KLMN;0″

    • Expected content of the output file after the second scan should be:

    “Time;””AlarTxt””;””AlmPrio””;””Almusr””;””acksts”””
    “2023-05-03 00:00:06;””sample text6″”;200;KLMN;0″
    “2023-05-03 00:00:06;””sample text7″”;200;KLMN;1″
    “2023-05-03 00:00:08;””sample text8″”;200;KLMN;0″
    “2023-05-03 00:00:10;””sample text9″”;200;KLMN;1″
    “2023-05-03 00:00:12;””sample text10″”;200;KLMN;0″

     

    A: This should be possible using our scripting option. We created a script that will keep the data of the csv files it already handled in a separate folder (= memory folder). These memory files will be used during next scans to only create output files where the content has new data.

    For the test, we added 3 folders:

    • Input
    • Memory
    • Output

    Be sure the ‘Memory’ folder is a local folder on the system where our File Mover is running.

    Modified contents of a file example

    Our Source will be the Input folder:

    Limagito file mover using WIN as source

    We added ‘*.csv’ as Filename Include filter because we only want to scan for csv files:

    limagito file mover filename filter

    Optional: we changed the ‘Source File Sort Order’ option to ‘File last write date ascending (Old to New)’. This will handle the oldest csv files first.

    limagito file mover scan older files first

    The function is set to ‘Copy Files’:

    limagito file mover function setup

    As Destination we’ll use our ‘Pascal Script’ option:

    You’ll need to adjust the following 2 constant values ( always end the constant with a \ ):

    • ctMemPath ( = path were we’ll keep our memory data )
    • ctOutPath ( = output path)

    We added a timestamp to the output filename. The format we used is ‘YYYYMMDDHHNNSS’. The reason we did this is to prevent data loss (in case the next system would not pickup the output files).

     

    Var
      tmpEntry, tmpText, tmpFileIn, tmpFileMem, tmpFileOut, tmpFileExtIn, tmpFileExtOut: String;
      tmpList, tmpListMem: TStringList;
    Const
      ctMemPath = 'C:\Test\Astra\Memory\';
      ctOutPath = 'C:\Test\Astra\Output\';
    Begin
      psExitCode:= 0;
      tmpFileIn := psFilePath + psFileName;
      tmpFileMem := ctMemPath + psFileName;
      tmpFileExtIn := ExtractFileExt(psFileName);
      tmpFileExtOut := '.' + FormatDateTime('YYYYMMDDHHNNSS', Now) + tmpFileExtIn;
      tmpFileOut := psStringReplace(psFileName, tmpFileExtIn, tmpFileExtOut);
      tmpFileOut := ctOutPath + tmpFileOut; 
      // Create Var
      tmpList := TStringList.Create; tmpListMem := TStringList.Create;
      Try
        Try 
          tmpList.LoadFromFile(tmpFileIn);
          // Check if file is already available in Memory folder
          If tmpList.Count > 1 Then
          Begin
            tmpEntry := tmpList.Strings[0]; tmpText := tmpList.Text; 
            If FileExists(tmpFileMem) Then
            Begin
              psLogWrite(1, '', psFileName + ' available in memory folder: ' + ctMemPath);                 
              Try
                tmpListMem.LoadFromFile(tmpFileMem);                          
                tmpList.Text := psStringReplace(tmpText, tmpListMem.Text, '');
                // tmpList.Insert(0, tmpEntry);
                psExitCode := 1;         
              Except
                psLogWrite(1, '', 'Error loading data from: ' + tmpFileMem);
              End;          
            End Else
            Begin
              psExitCode := 1;
              psLogWrite(1, '', psFileName + ' not available in memory folder: ' + ctMemPath);               
            End;  
            If tmpList.Count > 1 Then
            Begin  
              // Save to output folder
              If psExitCode = 1 Then 
              Begin
                psExitCode := 0;
                Try
                  psLogWrite(1, '', 'Saving data to: ' + tmpFileOut);       
                  tmpList.SaveToFile(tmpFileOut);
                  psExitCode := 1;
                Except
                  psLogWrite(1, '', 'Error saving data to: ' + tmpFileOut);
                End;  
              End;
              // Save to Memory folder      
              If psExitCode = 1 Then
              Begin
                psExitCode := 0;
                Try
                  psLogWrite(1, '', 'Saving data to: ' + tmpFileMem);
                  tmpList.Text := tmpText; tmpList.Delete(0);       
                  tmpList.SaveToFile(tmpFileMem);
                  psExitCode := 1;
                Except
                  psLogWrite(1, '', 'Error saving data to: ' + tmpFileOut);
                End;          
              End;
            End;        
          End Else
            psLogWrite(1, '', 'No data available in: ' + tmpFileIn);   
        Except
          psLogWrite(1, '', 'Error loading data from: ' + tmpFileIn);
        End;
      Finally
        tmpList.free; tmpListMem.Free;
      End;
    End.

    limagito file mover pascal script as destination

    This blog article is just a basic example of the customers request and can be tweaked so that it meets your requirements. Just contact us if you need help.

    Don’t forget to add an extra Rule which will cleanup the Memory folder on regular basis.

    #FileTransfer #csv #scada #MFT

    If you need any info  about this ‘Copy only the modified contents of a file’ request, please let us know.

    Best regards,Limagito Team

1 6 7 8 9 10 11 12 27
SEARCH