Skip to main content
littlehorse3
Known Participant
Apr 22, 2016 7:54 PM UTC
Answered

How select 'real' next document?

Hello. I have a few opened documents in Photoshop. I changed it's order as showed bellow:

How can I select 'real' next document that is by the right of active? If I press Ctr+Tab or use the same script code I select only next opened.

Or how can I get this document list order information?

Thank you.

This topic is closed to new replies. Start a new post to keep the conversation going.
JJMack
JJMackCorrect answer
Community Expert
Apr 23, 2016 12:36 PM UTC

littlehorse3 wrote:

I know about app.documents array. But it contains documents in opening order.

Yes in the order that the document were open or created in Photoshop.  You can also find the document  names if  the new or need to be saved etc. if you want the change their order I would think you may need to save the ones that need saving close all document then open the documents in the order you want them in.   You can process the documents in any order you want.  I do not edit in Tabs. If you are trying to change the document tab order which you can do using Photoshop UI by dragging the tab order. Adobe Scriptlistener plug-in does not record that event so I do not think you can script changing the tab order any way other than closing all the open document then opening them in the order you want them to be in. Not a good thing to do.

Previous and next document is actions are relative the the active document position in the document array the code also treats the order as a ring  next after the last open document is the firs open document.  Adobe warns you if you create  action that use previous and next if you open additional document in the action  Next and previous may not work the way you expect. Adding Document can change which document is next and previous.

If you have 10 open document in Photoshop  so the are element 0 through 9 in the document array your working on document[4]  it is the active document. If you run a script and it opens new document document[10] element is added and become the active document document[10] the script is still in control and can make  document[4] again work it and then switch to any other open document  using some logic.  Action can only switch using previous and next  action need to know the order of the document  and know what happens to the order when the change the order closing and opening document if an action uses a script or plays an other action it better know what the scrip or action does the the number of open documents.  Previous and Next  work on documents the are open if documents are open and document are close.  What is  Previous and Next  can change. Actions can only do step step step nor the there are also conditional action steps the involve other actions using  Previous and Next can be quite complex.  Scripts can use logic the can leave notes in document metadata to help processing.

I also do not know for sure what you mean when you write Select 'real' next document? what makes any next document UnReal?

JJMack

3 replies

JJMack
Community Expert
Community Expert
Apr 23, 2016 2:34 AM UTC

Here is a script I wrote to open process all open document and opens a new document which a paste in a pixels layer for every open document containing the open documents current visible composite,  The script can the close all open documents but the new document that contains a layer for the documents that were open when the scrip was started,

/* ==========================================================

// 2016  John J. McAssey (JJMack)

// Stack the open Document Visible layer composite into a new 300 DPI document

// This script is supplied as is. It is provided as freeware.

// The author accepts no liability for any problems arising from its use.

// ======================================================= */

// enable double-clicking from Mac Finder or Windows Explorer

#target photoshop // this command only works in Photoshop CS2 and higher

// bring application forward for double-click events

app.bringToFront();

if (documents.length >= 2) { main(); }

else alert("multiple Document are not open in Photoshop");

///////////////////////////////////////////////////////////////////////////////

//                            main function                                  //

///////////////////////////////////////////////////////////////////////////////

function main() {

  var orig_ruler_units = app.preferences.rulerUnits;

  var orig_display_dialogs = app.displayDialogs;

  app.preferences.rulerUnits = Units.PIXELS; // set the ruler units to PIXELS

  app.displayDialogs = DialogModes.NO; // Set Dialogs off

  var closeDocs  = prompt("Should documents be Close without saving?", "Yes");

  var canvasSize = new Array(); // what size canvas is needed

  canvasSize=getDocDementions(); // get max width and height of open documents

  app.togglePalettes(); // toggle off palette so Photoshop will not need to update them

  var doc = app.documents.add( canvasSize[0], canvasSize[1], 300, "Stacked Opened Documents", NewDocumentMode.RGB, DocumentFill.TRANSPARENT ); // create a new document

  //for (var i=0;i<documents.length-1;i++) { // stack a layer for the open document into the new document

  for (var i=documents.length-2;i>-1;i--) { // stack a layer for the open document into the new document

  app.activeDocument = documents; // switch active document

  var layerName = app.activeDocument.name; // get document name

  app.activeDocument.selection.selectAll();           // select all

  try {app.activeDocument.selection.copy(true);} // copy composite of visible layers to clipboard

  catch (e) {try {app.activeDocument.selection.copy();} // copy composite of visible layers to clipboard

    catch (e) { } // empty

  }

  app.activeDocument.selection.deselect(); // deselect

  app.activeDocument = documents[documents.length-1]; // switch to newly created document

  try { app.activeDocument.paste(); } // paste on composite of visible layers

  catch (e) { app.activeDocument.artLayers.add(); } // add an empty layer

  app.activeDocument.activeLayer.name=layerName; // label layer with Document name

  }

  if ( closeDocs == "Yes" ) closeAllButOne(); // close all opened document except the newly created document

  app.togglePalettes(); // toggle user's palettes back on

  app.runMenuItem(charIDToTypeID(("FtOn"))); // fit the document to the screen

  app.displayDialogs = orig_display_dialogs; // Reset display dialogs

  app.preferences.rulerUnits = orig_ruler_units; // reset units to original settings

  }

///////////////////////////////////////////////////////////////////////////////

//                           main function end                               //

///////////////////////////////////////////////////////////////////////////////

function getDocDementions(){

    width=0;

  height=0;

  for (var i=0;i<documents.length;i++) { // look at open document sizes

     if (documents.width > width) width=documents.width;

  if (documents.height > height) height=documents.height;

  }

  return new Array(width, height); // return width and height

  }

function closeAllButOne(){ // close all opened document except the newly created document

  while  (documents.length>1) {

  app.activeDocument = documents[0];

  activeDocument.close(SaveOptions.DONOTSAVECHANGES);

  }

  }

Translate
JJMack
littlehorse3
Known Participant
Apr 23, 2016 10:53 AM UTC

Sorry but I don't understand how this can help me.

I know about app.documents array. But it contains documents in opening order.

Translate
JJMack
Community Expert
JJMackCommunity ExpertCorrect answer
Community Expert
Apr 23, 2016 12:36 PM UTC

littlehorse3 wrote:

I know about app.documents array. But it contains documents in opening order.

Yes in the order that the document were open or created in Photoshop.  You can also find the document  names if  the new or need to be saved etc. if you want the change their order I would think you may need to save the ones that need saving close all document then open the documents in the order you want them in.   You can process the documents in any order you want.  I do not edit in Tabs. If you are trying to change the document tab order which you can do using Photoshop UI by dragging the tab order. Adobe Scriptlistener plug-in does not record that event so I do not think you can script changing the tab order any way other than closing all the open document then opening them in the order you want them to be in. Not a good thing to do.

Previous and next document is actions are relative the the active document position in the document array the code also treats the order as a ring  next after the last open document is the firs open document.  Adobe warns you if you create  action that use previous and next if you open additional document in the action  Next and previous may not work the way you expect. Adding Document can change which document is next and previous.

If you have 10 open document in Photoshop  so the are element 0 through 9 in the document array your working on document[4]  it is the active document. If you run a script and it opens new document document[10] element is added and become the active document document[10] the script is still in control and can make  document[4] again work it and then switch to any other open document  using some logic.  Action can only switch using previous and next  action need to know the order of the document  and know what happens to the order when the change the order closing and opening document if an action uses a script or plays an other action it better know what the scrip or action does the the number of open documents.  Previous and Next  work on documents the are open if documents are open and document are close.  What is  Previous and Next  can change. Actions can only do step step step nor the there are also conditional action steps the involve other actions using  Previous and Next can be quite complex.  Scripts can use logic the can leave notes in document metadata to help processing.

I also do not know for sure what you mean when you write Select 'real' next document? what makes any next document UnReal?

Translate
JJMack