• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers

activeDocument array?

Participant ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Does Photoshop keep an array of it's activeDocuments? Not a list of the documents history, which is held in  documents. But Photoshop files that are currently open. So app.activeDocument[1] would be the document you used last and app.activeDocument[0] is the current one.

 

for (var i = 0; i < activeDocuments.length; i++)
{
 // Something
}

Obviously the above doesn't work. - But you get the idea.

 

Hopefully.

 

TOPICS
Actions and scripting , Windows

Views

439

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 11, 2023 Jan 11, 2023

Copy link to clipboard

Copied

Only one document can be active at one time. So, no, that is not stored in an array, just an application property.

You might be looking for app.documents instead, which has nothing to do with history.

 

Screenshot 2023-01-11 151050.png

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 12, 2023 Jan 12, 2023

Copy link to clipboard

Copied

 

var theDocs = app.documents;

for (var i = 0; i < theDocs.length; i++)
{
  msg += theDocs[i].name + "\n";
}
alert(msg)

That gives the cocuments that wer opened in order, which not quite what I was after. I'm sure I'll work something out.

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 12, 2023 Jan 12, 2023

Copy link to clipboard

Copied

You can write a script using notifications. Each time you switch to a new document, it will record its ID. Accordingly, having saved this data during the session, you can always restore the sequence of switching between documents. Closed documents can simply be skipped.

 

I wrote a script designed to be written to an action that allows you to remember a specific document and return to it later. Perhaps this will help you: How to change the order of open documents for an action? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jan 13, 2023 Jan 13, 2023

Copy link to clipboard

Copied

That's a clever script. Possibly overkill for my needs - My script is just grabbing or putting guides from one document to another - for a one shot/ one button script it just needs to work out is there a document with the same dimensions already open? And is it missing guides? 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 13, 2023 Jan 13, 2023

Copy link to clipboard

Copied

quote

it just needs to work out is there a document with the same dimensions already open? And is it missing guides? 


By @Ghoul Fool

 

I'd set variables for the target doc's width.value and height.value, then a conditional loop over the open doc's to see if it matched both variables and contained no guides – and if so, then add guides.
 

Edit: Something like this –

 

/*
Run on the source document containing guides
It is presumed that you have code to copy/paste guides, such as:
https://www.reflections-ibs.com/media/1241/guides-copy.jsx
https://www.reflections-ibs.com/media/1242/guides-paste.jsx
*/

#target photoshop

var targetWidth = activeDocument.width.value;
var targetHeight = activeDocument.height.value;

for (var i = 0; i < app.documents.length; i++) {
    activeDocument = app.documents[i];
    if (activeDocument.width.value === targetWidth && activeDocument.height.value === targetHeight && activeDocument.guides.length === 0) {
        alert("Paste Guides...");
    } else {
        alert("Don't Paste Guides!");
    }
}

 

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

Copies guides from the active document to all open documents of the same size:

var startRulerUnits = preferences.rulerUnits,
  startTypeUnits = preferences.typeUnits,
  doc = activeDocument,
  activeDocumentW = doc.width.value,
  activeDocumentH = doc.height.value;
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
if (doc.guides.length) {
  var guides = [];
  for (var i = 0; i < doc.guides.length; i++) {
    guides.push({ direction: doc.guides[i].direction, coordinate: doc.guides[i].coordinate })
  }
  var len = documents.length;
  for (var i = 0; i < len; i++) {
    var cur = documents[i];
    if (cur == doc) continue;
    activeDocument = cur;
    if (cur.width == activeDocumentW && cur.height == activeDocumentH && !cur.guides.length) {
      for (var x = 0; x < guides.length; x++) {
        cur.guides.add(guides[x].direction, guides[x].coordinate)
      }
    }
  }
}
activeDocument = doc;
app.preferences.rulerUnits = startRulerUnits
app.preferences.typeUnits = startTypeUnits

@Stephen_A_MarshI noticed your message when I sketched the code.

 

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jan 14, 2023 Jan 14, 2023

Copy link to clipboard

Copied

LATEST

@jazz-y – All good, I always hope that a more experienced scripter will post their code, even if I have already contributed code, that way we all benefit!

Likes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines