Tapatalk

Parametric Tools

Parametric Tools

2
NewbieNewbie
2

    Jul 13, 2007#1

    Has anyone experimented with using javascript to write parametric tools to run within UE? A simple example follows:

    Current File: file01
    Red,55
    blue,3,text
    yellow,100

    Suppose I would like to generate 100 files based on this file but with the numbers being randomly generated within user specified ranges... e.g.

    Script generated: file02
    Red,6
    blue,36,text
    yellow,64

    In practice the file would be large (e.g. 60+Mb), with 10-50 variables and I would like to embed the parametric variables at different positions in lines based on a master file e.g.

    Master File: file
    Red,$a
    blue,$b,text
    yellow,$c

    With a scripted interface to let me define ranges for these variables. The files in question are column formated rather than CSV, but I assume that is not too much of a problem...

    My questions are: Is this possible within UE? Is there anything similar already out there (could also be called a DOE tool)? Anyone have some examples of the type of js code required to do this (I have no js experience, but I do have quite a bit of experience in other languages - fortran, php, etc.). Thanks.

    262
    MasterMaster
    262

      Jul 13, 2007#2

      Hi Agrox

      I have experimented a bit. First I create a template for the master file and assign it to template index 0 - Advanced - Display/Modify templates...

      It has the following contents:

      Code: Select all

      File....: [FULL_FILE_NAME]
      Red.....: $a
      Blue....: $b,text
      Yellow..: $c
      Created.: [DATE_DMY] [TIME]
      
      I chose template because I can then use the extra template variables for date, time and file info, like [TIME]. See the UE help for further explanations.

      Then I created this script:

      Code: Select all

      var numberOfGeneratedFiles = 2;
      var filePath = "C:\\temp\\";
      var filePrefix = "autoGenFileNo";
      var fileExt = "txt";
      var fullFilePath;
      
      var parmVars;
      var parmLow;
      var parmHigh;
      var parmValue;
      setupVars();
      
      for (f = 0; f < numberOfGeneratedFiles; f++) {
      	calculateVars();
      
      	UltraEdit.newFile();
      	fullFilePath = filePath+filePrefix+f+"."+fileExt;
      	UltraEdit.saveAs(fullFilePath); /* save as so we can utilize template variables like [FULL_FILE_NAME] */
      
      	UltraEdit.activeDocument.insertTemplate(0); /* now insert master file */
      	replaceVars();
      //	UltraEdit.closeFile(UltraEdit.activeDocument.path,1); /* save and close - uncomment */
      	UltraEdit.save();
      }
      
      /* ------------- */
      function setupVars() {
      	parmVars = new Array();
      	parmLow = new Array();
      	parmHigh = new Array();
      	parmValue = new Array();
      
      	parmVars.push("a"); parmLow.push(10);   parmHigh.push(19);     parmValue.push(-1);
      	parmVars.push("b"); parmLow.push(100);  parmHigh.push(999);    parmValue.push(-1);
      	parmVars.push("c"); parmLow.push(1);    parmHigh.push(1000);   parmValue.push(-1);
      }
      /* ------------- */
      function replaceVars() {
      	UltraEdit.activeDocument.findReplace.replaceAll=true;
      	for (i in parmVars) {
      		UltraEdit.activeDocument.findReplace.replace("$"+parmVars[i],""+parmValue[i]);
      	}
      }
      /* ------------- */
      function calculateVars() {
      	for (i in parmVars) {
      		parmValue[i] = parmLow[i] + Math.floor(Math.random()*(parmHigh[i]-parmLow[i]));
      	}
      }
      You define how many generated files you want (2 in my example). The setupVars() function defines the variable and low and high limit for random numbers.

      Then the script iterates to generate the number of files wanted. The template is inserted and it is searched/replaced for the variables. The variables are recalculated in each loop.

      I hope this is an inspiration for you. With PHP experience I don't think it is too difficult to decipher. Otherwise have a look at the javascript resources linked in the script sticky.

      Only one thing I didn't consider for this solution: Large files of 60+MB. This might call for a slightly different solution than templates.

      2
      NewbieNewbie
      2

        Jul 14, 2007#3

        Many thanks for your help and code example - that was exactly what I was looking for; I'm away for a few days now, but I will take a look at this next week.