PhotoShop Script: Apply "Flip Horizontal" to all open windows (including clones)

Viewed 35

Ive been trying to apply the View -- Flip Horizontal to all my open documents when working in some illustrations with an Script (the script is pretty simple) But I need to focus on the windows open that include "Clone windows" of the working documents. My problem is that the script sequentially jumps through the documents, but the "clone documents" does not appear as a new document (because it is just a new window that mirror the document). For reference is when you do window -> arrange -> new ****.PSD

This is my code:

var idflipViewHorizontal = stringIDToTypeID( "flipViewHorizontal" );  
var workingDocument = app.activeDocument;  
for (var i = 0; i < app.documents.length; i++)  
{
app.activeDocument = app.documents[i];  
var docRef = app.activeDocument;

runMenuItem(idflipViewHorizontal);
};  
app.activeDocument = workingDocument;

BUt This just cycle through documents, and I need cycle through open windows, to apply the "view effect" cause this view -- flip horizontal doesnt actually change the doc, it is just a view mode.

1 Answers

This will loop over documents and flip the image.

var workingDocument = app.activeDocument;

for (var i = 0; i < documents.length; i++)  
{
  app.activeDocument = documents[i];

  // flip it
  app.activeDocument.flipCanvas(Direction.HORIZONTAL);
}

app.activeDocument = workingDocument;

Since you are flipping for artistic reasons, this may get very slow with large psd files, so as a compromise can I suggest a similar tactic where a duplicate of the image is created & flattened & flipped quickly - keeping the source untouched.

var workingDocument = app.activeDocument; 

// make deep copy of documents
// otherwise when we loop over it and duplicate 
// - we run into trouble
var docs = [];
for (var i = 0; i < documents.length; i++)
{
  docs[i] = app.documents[i];
}


for (var i = 0; i < docs.length; i++)  
{
  app.activeDocument = docs[i];

  // duplicate image into new document
  duplicate_it("temp " + (i+1));

  // flatten it
  flatten_it();

  // flip it
  app.activeDocument.flipCanvas(Direction.HORIZONTAL);
}

app.activeDocument = workingDocument;


// function FLATTEN IT ()
// ----------------------------------------------------------------
function flatten_it()
{
  activeDocument.flatten();
}


// function DUPLICATE IT (str)
// --------------------------------------------------------
function duplicate_it(str)
{
  // duplicate image into new document
  if (arguments.length == 0) str = "temp";

  var id428 = charIDToTypeID( "Dplc" );
  var desc92 = new ActionDescriptor();
  var id429 = charIDToTypeID( "null" );
  var ref27 = new ActionReference();
  var id430 = charIDToTypeID( "Dcmn" );
  var id431 = charIDToTypeID( "Ordn" );
  var id432 = charIDToTypeID( "Frst" );
  ref27.putEnumerated( id430, id431, id432 );
  desc92.putReference( id429, ref27 );
  var id433 = charIDToTypeID( "Nm  " );
  desc92.putString( id433, str ); // name
  executeAction( id428, desc92, DialogModes.NO );
}
Related