Copy link to clipboard
Copied
Hi!
e.g.
I have a book with 15 Documents. I mark the docs in the book-palette and open them with a double click.
When they are all opened I want to ask how many pages each of them has. The script works, that´s not the problem.
My question is: In what order do the documents open? In the list that I have issued, they are mixed up. Why?
Copy link to clipboard
Copied
var myDoc = app.documents;
app.activeDocument = myDoc[1];
Okay, I found that the object with key 1 is not necessarily the second document.
Hmmm....
Copy link to clipboard
Copied
I do not have the anwer yet, but a solution to sort the opened documents ascending:
var myDoc = app.documents;
var docsLength = myDoc.length;
myArray= new Array();
mySortedDocs= new Array();
mySortedIDs= new Array();
for (i=0; i<docsLength; i++) {
var myDoc = app.documents;
var docsLength = myDoc.length;
myArray= new Array();
mySortedDocs= new Array();
mySortedIDs= new Array();
for (i=0; i<docsLength; i++) {
mySortedDocs.push(myDoc[i]);
//~ mySortedIDs.push(myDoc[i].index);
}
mySortedDocs.sort(function (a) {return (a.name)});
//~ mySortedIDs.sort();
for (i=0; i<docsLength; i++) {
myArray.push(mySortedDocs[i].name + ": has the Index " + mySortedDocs[i].index + "\r");//
}
alert(myArray.join("\r"));
But why does the list start with second document, with the index 1? The name of all the document starts witz a number (01_, 02_, 03_). Newerthenless it starts with 02_.... .indd!
The document 01_.... .indd ist the last one in the list.
Copy link to clipboard
Copied
Hi cmoke73,
no idea. I tested a book with some documents. Selected all the documents and did a double-click not to the first one in the stack and they all opened in the order of the book's bookContents.
Hm. Perhaps the order is in creation order or in order of the modification date of the document files? I did not test this.
If you want to open the documents in order of the bookContents do it like that:
var docFilesInBook = app.books[0].bookContents.everyItem().fullName;
for( var n=0; n<docFilesInBook.length; n++ )
{
app.open( docFilesInBook[n] , true , OpenOptions.OPEN_ORIGINAL );
};
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
It´s a good hint. Thanks
But not the answer. 🙂
Do you know why in a sorted array the first object isn´t the one with the name 01_... ? 😞
Copy link to clipboard
Copied
But the array is not *sorted* in any way. Opening the documents in BookContents order is my idea as well, if you want to be sure of a certain order.
Unfortunately, my experience with InDesign is that the Documents order is ... flaky, random, buggy, and supremely annoying, all at the same time. I have tons of documents open on a regular basis, and there seems to be no rhyme or rule as to what newly opened document gets inserted where in the Documents list (and what happens with the rest), and where they will appear in the Tabs list at the top. And what document you will get when you press "Ctrl+Tab" to navigate to the 'next' tab -- for some reason it never is the one immediately to the right of the current viewed doc.
(</rant>, sorry.)
Copy link to clipboard
Copied
Hi Jongware.
If YOU are the one with this opinion, wow! No chance of finding a solution. 🙂 🙂
Not the worst of my problems. But I have to work with the open documents. It's part of my workflow. The following script is almost what I need. But at some point there was an error: "null is not an object":
var myDoc = app.documents;
var docsLength = myDoc.length;
myArray= new Array();
mySortedDocs= new Array();
myPages = new Array();
mySortedIDs= new Array();
mySortedDocsName = new Array();
allGraphicsArray = new Array();
myGraphicsArray = new Array();
//////////////////////////////////////////////// OUTER LOOP ////////////////////////////////////////////////
for (i=0; i<docsLength; i++) {
mySortedDocs.push(myDoc[i]);
var pages = myDoc[i].pages;
//////////////////////////////////////////////// INNER LOOP ////////////////////////////////////////////////
for (n=0; n<pages.length;n++) {
if(pages.length > 0) {
myPages.push(mySortedDocs[i].pages[n]);
allGraphicsArray = mySortedDocs[i].pages[n].allGraphics;
var graphLength = mySortedDocs[i].pages[n].allGraphics.length;
//////////////////////////////////////////////// CORE LOOP ////////////////////////////////////////////////
for(t=0;t<graphLength;t++) {
if(allGraphicsArray[t].parent.itemLayer.visible === true){
//alert(mySortedDocs[i].name + " " + pages[n].name + " " + allGraphicsArray[t].itemLink.name);
var objName = allGraphicsArray[t].itemLink.name;
if(objName === "SF_Icon_72h_2020.ai"){
myGraphicsArray.push(allGraphicsArray[t]);
}//IF-END
}
}// FOR-END
////////////////////////////////////////////////////////////////////////////////////////////////
}// IF-END
} // FOR-END
////////////////////////////////////////////////////////////////////////////////////////////////
} // FOR-END
////////////////////////////////////////////////////////////////////////////////////////////////
alert(myGraphicsArray.length);
Copy link to clipboard
Copied
Hi,
could be that one graphic is not placed and linked, but was pasted to your document.
Then there is no itemLink with the graphic.
Regards,
Uwe Laubender
( ACP )
Copy link to clipboard
Copied
Oh, it was nearly proper. I added a supplementary condition in the line:
if(allGraphicsArray[t].parent.itemLayer.visible === true && allGraphicsArray[t].constructor.name === "PDF"){ ... }
There is a psd-Image in one of the documents wich causes the error. Don´t know why. It´s not embeded.
Because I´m only looking for pdfs, I sorted all others out now.
Anway, thanks.
Copy link to clipboard
Copied
deleted
Find more inspiration, events, and resources on the new Adobe Community
Explore Now