automating an action from a sequence of images

Discussion of Automation, Image Workflow and Raw Image Workflow

Moderators: Tom, Kukurykus

Mcquiff

automating an action from a sequence of images

Post by Mcquiff »

I have an action setup in Photoshop that selects to pictures and processes them. No I have a lot of files that need processing, How can I script it so that it takes the images in sequence.

For examples I have files 1-10 labeled image001.jpg, image002.jpg ….

The Script would need to take image001.jpg and image002.jpg

Run action

Then take the next in sequence

image003.jpg and image004.jpg


Run action until sequence complete.


In terms of selecting the items. It could be everything in the folder or highlighting them in finder?

Many Thanks

Matt
txuku

automating an action from a sequence of images

Post by txuku »

Bonjour Mcquiff

If I understand what you want this script should be able to help you.

put the work involved (call functions) line 25 :

Code: Select allapp.displayDialogs = DialogModes.NO
var strtRulerUnits = preferences.rulerUnits
preferences.rulerUnits = Units.PIXELS

//var inputFolder =  new Folder("C:/Users/moi/Mes documents/Mes images/Z_TRAITEMENT_TIFFS")
inputFolder =  Folder.selectDialog("Selectionner le DOSSIER DES IMAGES A TRAITER")

var fileList = inputFolder.getFiles();

var j=1;

while(j<fileList.length+1)
{
  for(k=0;k<2;k++)
  {
    OpenFolder(inputFolder);
    var docName = activeDocument.name;
    j=j+1;
  }
 
  //test si une image est seule ouverte elle n est pas traitee ( nombre impair d images)
  try
  {
  documents[1].exist==true;
  //travail a faire - appel de fonctions - work to do
  alert("pour tester le script");
  }
  catch(e){ alert(" il n y a plus qu un document impair");}

  //fermer les 2 images ouvertes sans sauver
  while(documents.length>0)
  {
    documents[documents.length-1].close(SaveOptions.DONOTSAVECHANGES);
  }
}

//test impair

if (fileList.length/2!=Math.round(fileList.length/2))
{
  alert(" il  y a un document non traite : " + docName );
}



function OpenFolder(inputFolder)
{
  filesOpened = 0;
        for (  i = 0; i < fileList.length; )
        {
         
          fileName = fileList.name;
         
          fileName1 = fileName.substring( 0, fileName.length-4);
          //alert(fileName1)
          NB = fileName1.slice(-3)
          //alert(NB)
          if(j<10)
          {
            NBf = "00"+j;
            if(NBf==NB){ open( fileList ); }
          }
          else if(j>9)
          {
            NBf = "0"+j;
            if(NBf==NB){ open( fileList ); }
          }
         
          i++; 
        }
          return filesOpened;
}

Mcquiff

automating an action from a sequence of images

Post by Mcquiff »

Thanks for getting back,

I got the error

Line: 17
-> var docName = activeDocument.name;



I thought i would post the script it was trying to run.

Code: Select all#target photoshop
//
// DifferenceofLayers.jsx
//

//
// Generated Mon Dec 12 2011 17:23:49 GMT-0000
//

cTID = function(s) { return app.charIDToTypeID(s); };
sTID = function(s) { return app.stringIDToTypeID(s); };

//
//==================== Difference of Layers ==============
//
function DifferenceofLayers() {
  // Scripts
  function step1(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var estr = '//@include "/Applications/CS5/Presets/Scripts/Load%20Files%20into%20Stack.jsx";\r\n';
    eval(estr);
  };

  // Set
  function step2(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(cTID('Nm  '), "Main Image");
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Select
  function step3(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Bckw'));
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Set
  function step4(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(cTID('Nm  '), "Negative Main Image");
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Select
  function step5(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Lyr '), "Main Image");
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Set
  function step6(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Dfrn'));
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble(cTID('Scl '), cTID('#Prc'), 100);
    desc2.putObject(cTID('Lefx'), cTID('Lefx'), desc3);
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Select All Layers
  function step7(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    executeAction(sTID('selectAllLayers'), desc1, dialogMode);
  };

  // Move
  function step8(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putIndex(cTID('Lyr '), 0);
    desc1.putReference(cTID('T   '), ref2);
    desc1.putBoolean(cTID('Dplc'), true);
    desc1.putBoolean(cTID('Adjs'), false);
    desc1.putInteger(cTID('Vrsn'), 5);
    executeAction(cTID('move'), desc1, dialogMode);
  };

  // Merge Layers
  function step9(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(sTID('mergeLayersNew'), undefined, dialogMode);
  };

  // Set
  function step10(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(cTID('Nm  '), "Mask");
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Subtract From
  function step11(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putProperty(cTID('Chnl'), sTID("selection"));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), 444);
    desc2.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), 390);
    desc1.putObject(cTID('T   '), cTID('Pnt '), desc2);
    desc1.putInteger(cTID('Tlrn'), 16);
    desc1.putBoolean(cTID('AntA'), true);
    desc1.putBoolean(cTID('Cntg'), false);
    executeAction(sTID('subtractFrom'), desc1, dialogMode);
  };

  // Refine Edge
  function step12(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putUnitDouble(sTID("refineEdgeBorderRadius"), cTID('#Pxl'), 0.1);
    desc1.putUnitDouble(sTID("refineEdgeBorderContrast"), cTID('#Prc'), 33);
    desc1.putInteger(sTID("refineEdgeSmooth"), 2);
    desc1.putUnitDouble(sTID("refineEdgeFeatherRadius"), cTID('#Pxl'), 0);
    desc1.putUnitDouble(sTID("refineEdgeChoke"), cTID('#Prc'), 5);
    desc1.putBoolean(sTID("refineEdgeAutoRadius"), true);
    desc1.putBoolean(sTID("refineEdgeDecontaminate"), true);
    desc1.putUnitDouble(sTID("refineEdgeDeconWeight"), cTID('#Prc'), 50);
    desc1.putEnumerated(sTID("refineEdgeOutput"), sTID("refineEdgeOutput"), sTID("refineEdgeOutputSheetAndMask"));
    executeAction(sTID('refineSelectionEdge'), desc1, dialogMode);
  };

  // Select
  function step13(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Make
  function step14(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putClass(cTID('Nw  '), cTID('Chnl'));
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
    ref1.putName(cTID('Lyr '), "Main Image");
    desc1.putReference(cTID('At  '), ref1);
    var ref2 = new ActionReference();
    ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
    ref2.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('Usng'), ref2);
    desc1.putBoolean(cTID('Dplc'), true);
    executeAction(cTID('Mk  '), desc1, dialogMode);
  };

  // Select
  function step15(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
    ref1.putName(cTID('Lyr '), "Main Image");
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Invert
  function step16(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    executeAction(cTID('Invr'), undefined, dialogMode);
  };

  // Set
  function step17(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Nrml'));
    var desc3 = new ActionDescriptor();
    desc3.putUnitDouble(cTID('Scl '), cTID('#Prc'), 100);
    desc2.putObject(cTID('Lefx'), cTID('Lefx'), desc3);
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Hide
  function step18(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var list1 = new ActionList();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Lyr '), "Mask copy");
    list1.putReference(ref1);
    desc1.putList(cTID('null'), list1);
    executeAction(cTID('Hd  '), desc1, dialogMode);
  };

  // Make
  function step19(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putClass(cTID('Lyr '));
    desc1.putReference(cTID('null'), ref1);
    executeAction(cTID('Mk  '), desc1, dialogMode);
  };

  // Fill
  function step20(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    desc1.putEnumerated(cTID('Usng'), cTID('FlCn'), cTID('BckC'));
    desc1.putUnitDouble(cTID('Opct'), cTID('#Prc'), 100);
    desc1.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Nrml'));
    executeAction(cTID('Fl  '), desc1, dialogMode);
  };

  // Move
  function step21(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var ref2 = new ActionReference();
    ref2.putIndex(cTID('Lyr '), 3);
    desc1.putReference(cTID('T   '), ref2);
    desc1.putBoolean(cTID('Adjs'), false);
    desc1.putInteger(cTID('Vrsn'), 5);
    executeAction(cTID('move'), desc1, dialogMode);
  };

  // Set
  function step22(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(cTID('Nm  '), "BACKGROUND");
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Select
  function step23(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Lyr '), "Mask copy");
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Set
  function step24(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    var desc2 = new ActionDescriptor();
    desc2.putString(cTID('Nm  '), "Original Image");
    desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
    executeAction(cTID('setd'), desc1, dialogMode);
  };

  // Select
  function step25(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Lyr '), "Negative Main Image");
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Select
  function step26(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Lyr '), "Mask");
    desc1.putReference(cTID('null'), ref1);
    desc1.putEnumerated(sTID("selectionModifier"), sTID("selectionModifierType"), sTID("addToSelection"));
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  // Delete
  function step27(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
    desc1.putReference(cTID('null'), ref1);
    executeAction(cTID('Dlt '), desc1, dialogMode);
  };

  // Select
  function step28(enabled, withDialog) {
    if (enabled != undefined && !enabled)
      return;
    var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
    var desc1 = new ActionDescriptor();
    var ref1 = new ActionReference();
    ref1.putName(cTID('Lyr '), "Main Image");
    desc1.putReference(cTID('null'), ref1);
    desc1.putBoolean(cTID('MkVs'), false);
    executeAction(cTID('slct'), desc1, dialogMode);
  };

  step1();      // Scripts
  step2();      // Set
  step3();      // Select
  step4();      // Set
  step5();      // Select
  step6();      // Set
  step7();      // Select All Layers
  step8();      // Move
  step9();      // Merge Layers
  step10();      // Set
  step11();      // Subtract From
  step12();      // Refine Edge
  step13();      // Select
  step14();      // Make
  step15();      // Select
  step16();      // Invert
  step17();      // Set
  step18();      // Hide
  step19();      // Make
  step20();      // Fill
  step21();      // Move
  step22();      // Set
  step23();      // Select
  step24();      // Set
  step25();      // Select
  step26();      // Select
  step27();      // Delete
  step28();      // Select
};



//=========================================
//                    DifferenceofLayers.main
//=========================================
//

DifferenceofLayers.main = function () {
  DifferenceofLayers();
};

DifferenceofLayers.main();

// EOF

"DifferenceofLayers.jsx"
// EOF
txuku

automating an action from a sequence of images

Post by txuku »

difficult for me .....
I try to mix the two:

Code: Select all  #target photoshop
    //
    // DifferenceofLayers.jsx
    //

    //
    // Generated Mon Dec 12 2011 17:23:49 GMT-0000
    //

    cTID = function(s) { return app.charIDToTypeID(s); };
    sTID = function(s) { return app.stringIDToTypeID(s); };




app.displayDialogs = DialogModes.NO;
var strtRulerUnits = preferences.rulerUnits;
preferences.rulerUnits = Units.PIXELS;

//var inputFolder =  new Folder("C:/Users/moi/Mes documents/Mes images/ImagesPAIRES")//Z_TRAITEMENT_TIFFS")
var inputFolder =  Folder.selectDialog("Selectionner le DOSSIER DES IMAGES A TRAITER")

var fileList = inputFolder.getFiles();

var j=1;
var l=0;

while(j<fileList.length+1)
{
  for(k=0;k<2;k++)
  {
    OpenFolder(inputFolder);
    //var docName = activeDocument.name;
   
    j=j+1;
  }
 
  //test si une image est seule ouverte elle n est pas traitee ( nombre impair d images)
  try
  {   
     
      activeDocument = app.documents[l]; 
      activeDocument.selection.selectAll();
      activeDocument.selection.copy();
      activeDocument.paste()
      activeDocument.selection.deselect();
      activeDocument.activeLayer=activeDocument.layers[1];
      activeDocument.activeLayer.remove();
      l=l+1; 
      activeDocument = app.documents[l]; 
      activeDocument.selection.selectAll();
      activeDocument.selection.copy();
      activeDocument.close(SaveOptions.DONOTSAVECHANGES);
      activeDocument.paste();
      activeDocument.activeLayer=activeDocument.layers[1];
     
      DifferenceofLayers();

  }
  catch(e){ alert(" il n y a plus qu un document impair"); activeDocument.close(SaveOptions.DONOTSAVECHANGES);}


}



function OpenFolder(inputFolder)
{
  filesOpened = 0;
        for (  i = 0; i < fileList.length; )
        {
         
          fileName = fileList.name;
         
          fileName1 = fileName.substring( 0, fileName.length-4);
          //alert(fileName1)
          NB = fileName1.slice(-3)
          //alert(NB)
          if(j<10)
          {
            NBf = "00"+j;
            if(NBf==NB){ open( fileList ); }
          }
          else if(j>9)
          {
            NBf = "0"+j;
            if(NBf==NB){ open( fileList ); }
          }
         
          i++; 
        }
          return filesOpened;
}


    //
    //==================== Difference of Layers ==============
    //
    function DifferenceofLayers() {
      // Scripts
      function step1(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var estr = '//@include "C:/Users/moi/Mes documents/JAVA_SCRIPT_W/SIMPLIFIES/Load_Files_into_Stack.jsx";\r\n';
       
        //"/Applications/CS5/Presets/Scripts/Load%20Files%20into%20Stack.jsx";\r\n';
        eval(estr);
      };




      // Set
      function step2(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putString(cTID('Nm  '), "Main Image");
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Select
      function step3(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Bckw'));
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Set
      function step4(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putString(cTID('Nm  '), "Negative Main Image");
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Select
      function step5(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putName(cTID('Lyr '), "Main Image");
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Set
      function step6(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Dfrn'));
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble(cTID('Scl '), cTID('#Prc'), 100);
        desc2.putObject(cTID('Lefx'), cTID('Lefx'), desc3);
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Select All Layers
      function step7(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        executeAction(sTID('selectAllLayers'), desc1, dialogMode);
      };

      // Move
      function step8(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var ref2 = new ActionReference();
        ref2.putIndex(cTID('Lyr '), 0);
        desc1.putReference(cTID('T   '), ref2);
        desc1.putBoolean(cTID('Dplc'), true);
        desc1.putBoolean(cTID('Adjs'), false);
        desc1.putInteger(cTID('Vrsn'), 5);
        executeAction(cTID('move'), desc1, dialogMode);
      };

      // Merge Layers
      function step9(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        executeAction(sTID('mergeLayersNew'), undefined, dialogMode);
      };

      // Set
      function step10(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putString(cTID('Nm  '), "Mask");
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Subtract From
      function step11(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putProperty(cTID('Chnl'), sTID("selection"));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putUnitDouble(cTID('Hrzn'), cTID('#Rlt'), 444);
        desc2.putUnitDouble(cTID('Vrtc'), cTID('#Rlt'), 390);
        desc1.putObject(cTID('T   '), cTID('Pnt '), desc2);
        desc1.putInteger(cTID('Tlrn'), 16);
        desc1.putBoolean(cTID('AntA'), true);
        desc1.putBoolean(cTID('Cntg'), false);
        executeAction(sTID('subtractFrom'), desc1, dialogMode);
      };

      // Refine Edge
      function step12(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        desc1.putUnitDouble(sTID("refineEdgeBorderRadius"), cTID('#Pxl'), 0.1);
        desc1.putUnitDouble(sTID("refineEdgeBorderContrast"), cTID('#Prc'), 33);
        desc1.putInteger(sTID("refineEdgeSmooth"), 2);
        desc1.putUnitDouble(sTID("refineEdgeFeatherRadius"), cTID('#Pxl'), 0);
        desc1.putUnitDouble(sTID("refineEdgeChoke"), cTID('#Prc'), 5);
        desc1.putBoolean(sTID("refineEdgeAutoRadius"), true);
        desc1.putBoolean(sTID("refineEdgeDecontaminate"), true);
        desc1.putUnitDouble(sTID("refineEdgeDeconWeight"), cTID('#Prc'), 50);
        desc1.putEnumerated(sTID("refineEdgeOutput"), sTID("refineEdgeOutput"), sTID("refineEdgeOutputSheetAndMask"));
        executeAction(sTID('refineSelectionEdge'), desc1, dialogMode);
      };

      // Select
      function step13(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Make
      function step14(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        desc1.putClass(cTID('Nw  '), cTID('Chnl'));
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
        ref1.putName(cTID('Lyr '), "Main Image");
        desc1.putReference(cTID('At  '), ref1);
        var ref2 = new ActionReference();
        ref2.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
        ref2.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('Usng'), ref2);
        desc1.putBoolean(cTID('Dplc'), true);
        executeAction(cTID('Mk  '), desc1, dialogMode);
      };

      // Select
      function step15(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Chnl'), cTID('Chnl'), cTID('Msk '));
        ref1.putName(cTID('Lyr '), "Main Image");
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Invert
      function step16(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        executeAction(cTID('Invr'), undefined, dialogMode);
      };

      // Set
      function step17(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Nrml'));
        var desc3 = new ActionDescriptor();
        desc3.putUnitDouble(cTID('Scl '), cTID('#Prc'), 100);
        desc2.putObject(cTID('Lefx'), cTID('Lefx'), desc3);
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Hide
      function step18(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var list1 = new ActionList();
        var ref1 = new ActionReference();
        ref1.putName(cTID('Lyr '), "Mask copy");
        list1.putReference(ref1);
        desc1.putList(cTID('null'), list1);
        executeAction(cTID('Hd  '), desc1, dialogMode);
      };

      // Make
      function step19(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putClass(cTID('Lyr '));
        desc1.putReference(cTID('null'), ref1);
        executeAction(cTID('Mk  '), desc1, dialogMode);
      };

      // Fill
      function step20(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        desc1.putEnumerated(cTID('Usng'), cTID('FlCn'), cTID('BckC'));
        desc1.putUnitDouble(cTID('Opct'), cTID('#Prc'), 100);
        desc1.putEnumerated(cTID('Md  '), cTID('BlnM'), cTID('Nrml'));
        executeAction(cTID('Fl  '), desc1, dialogMode);
      };

      // Move
      function step21(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var ref2 = new ActionReference();
        ref2.putIndex(cTID('Lyr '), 3);
        desc1.putReference(cTID('T   '), ref2);
        desc1.putBoolean(cTID('Adjs'), false);
        desc1.putInteger(cTID('Vrsn'), 5);
        executeAction(cTID('move'), desc1, dialogMode);
      };

      // Set
      function step22(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putString(cTID('Nm  '), "BACKGROUND");
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Select
      function step23(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putName(cTID('Lyr '), "Mask copie");
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Set
      function step24(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        var desc2 = new ActionDescriptor();
        desc2.putString(cTID('Nm  '), "Original Image");
        desc1.putObject(cTID('T   '), cTID('Lyr '), desc2);
        executeAction(cTID('setd'), desc1, dialogMode);
      };

      // Select
      function step25(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putName(cTID('Lyr '), "Negative Main Image");
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Select
      function step26(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putName(cTID('Lyr '), "Mask");
        desc1.putReference(cTID('null'), ref1);
        desc1.putEnumerated(sTID("selectionModifier"), sTID("selectionModifierType"), sTID("addToSelection"));
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

      // Delete
      function step27(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putEnumerated(cTID('Lyr '), cTID('Ordn'), cTID('Trgt'));
        desc1.putReference(cTID('null'), ref1);
        executeAction(cTID('Dlt '), desc1, dialogMode);
      };

      // Select
      function step28(enabled, withDialog) {
        if (enabled != undefined && !enabled)
          return;
        var dialogMode = (withDialog ? DialogModes.ALL : DialogModes.NO);
        var desc1 = new ActionDescriptor();
        var ref1 = new ActionReference();
        ref1.putName(cTID('Lyr '), "Main Image");
        desc1.putReference(cTID('null'), ref1);
        desc1.putBoolean(cTID('MkVs'), false);
        executeAction(cTID('slct'), desc1, dialogMode);
      };

     // step1();      // Scripts
      step2();      // Set
      step3();      // Select
      step4();      // Set
      step5();      // Select
      step6();      // Set
      step7();      // Select All Layers
      step8();      // Move
      step9();      // Merge Layers
      step10();      // Set
      step11();      // Subtract From
      step12();      // Refine Edge
      step13();      // Select
      step14();      // Make
      step15();      // Select
      step16();      // Invert
      step17();      // Set
      step18();      // Hide
      step19();      // Make
      step20();      // Fill
      step21();      // Move
      step22();      // Set
      step23();      // Select
      step24();      // Set
      step25();      // Select
      step26();      // Select
      step27();      // Delete
      step28();      // Select
    };



    //=========================================
    //                    DifferenceofLayers.main
    //=========================================
    //

//    DifferenceofLayers.main = function () {
//      DifferenceofLayers();
//    };

  //  DifferenceofLayers.main();

    // EOF

Mcquiff

automating an action from a sequence of images

Post by Mcquiff »

Hi Thanks again.

It partly works, some of it is as a result of my the script i have has not added a save function.

I tried to add it, but that caused it not to work, as it then prompted me to select the files to load into a stack.

All that needs to be done is saved as a PSD in sequence as they get labeled later.

When it does load it appears to only load all of the odd numbered files except 0001.jpg

Also I found that it only likes to work if labeled from 0001.jpg as opposed to starting at 0010.jpg (i can always rename first)



I've included a sample of images if you run the my script as it is, you get a prompt to load files, select 0001.jpg and 0002.jpg and you will see what the end result should be.

Many Thanks

Matt