Copy link to clipboard
Copied
Hi All,
How can we use book concept (.indb). Actually i have script for override all master page item in the active Document only.
But I want to override all the BookContents in the active Book(.indb) (i.e., folio1.indd, folio2.indd, folio3.indd, folio4.indd, folio5.indd) see attachment.
Here is trying code:
For the single document only (working good):
var myDocument = app.activeDocument
var myPages = myDocument.pages;
for(i=0; i < myPages.length; i++) {
OverrideMasterItems();
}
function OverrideMasterItems() {
var allItems = myDocument.pages.appliedMaster.pageItems.everyItem().getElements();
for(var j=0;j<allItems.length;j++){
try{allItems
catch(e){}
}
}
But my requirement is override all master page item through book(.indb)
Trying code is (not working):
//Over writing the master page elements through Book(.indb)
var myBook = app.books[0]
var myBookContents =app.books[0].bookContents.everyItem().getElements()
var myPages = myBookContents.pages;
for(i=0; i < myPages.length; i++) {
OverrideMasterItems();
}
function OverrideMasterItems() {
var allItems = myBook.pages.appliedMaster.pageItems.everyItem().getElements();
for(var j=0;j<allItems.length;j++){
try{allItems
catch(e){}
}
}
I am the beginner. Book Concept is entirely new for me. Please anyone give solution.
For Reference kindly see the attachment
Thanks in advance
BEGINNER_X
Copy link to clipboard
Copied
Hi,
have a look at your variable
var myBookContents =app.books[0].bookContents.everyItem().getElements()
You'll see it's a array.
so
var currBookContent = myBookContents[0]
will give infos to a item bookContent.
currBookContent.fullName will return a fileobject to the corresponding document.
Check if the document is already open, if not open it, ... do stuff
Hope it'll help ...
Hans-Gerd Claßen
Copy link to clipboard
Copied
Hi Hans/All,
Thanks for your reply....
Using forum i got a script for open and close all the book contents. Its works fine.
Code is below (working good):
//Open all the Book Contents in the book
for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i--)
{
app.open (app.activeBook.bookContents.fullName, true)
}
////Close all the Book Contents in the book
for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )
{
app.open (app.activeBook.bookContents.fullName, false).close(SaveOptions.ASK);
}
But as per my requirement i want to open all the documents(bookContents) in the book, override all master page elements and close all the documents in the book
Trying Script is:
for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )
{
app.open (app.activeBook.bookContents.fullName, true)
bookOverrideMasterItems ()
app.open (app.activeBook.bookContents.fullName, false).close(SaveOptions.ASK);
}
function bookOverrideMasterItems()
{
var myDocument = app.open (app.activeBook.bookContents.fullName, true);
var myPages = myDocument.pages;
for(i=0; i < myPages.length; i++) {
OverrideMasterItems();
}
function OverrideMasterItems() {
var allItems = myDocument.pages.appliedMaster.pageItems.everyItem().getElements();
for(var j=0;j<allItems.length;j++){
try{
allItems
}
catch(e){}
}
}
}
Please find the screenshot of error and my book(.indb)
Copy link to clipboard
Copied
Hello BEGGINER_X,
Try the below JS code, try to analyze the code! you just copy and paste the code its workigng, but sometime you defintely lock. try to analyze!
for( var i = app.activeBook.bookContents.length-1 ; i>=0 ; i-- )
{
app.open (app.activeBook.bookContents.fullName, true)
bookOverrideMasterItems ()
}
function bookOverrideMasterItems()
{
var myDocument = app.open (app.activeBook.bookContents.fullName, true);
var myPages = myDocument.pages;
for(i=0; i < myPages.length; i++) {
var allItems = myDocument.pages.appliedMaster.pageItems.everyItem().getElements() ;
for(var j=0;j<allItems.length;j++){
try{
allItems
}
catch(e){}
}
}
myDocument.close(SaveOptions.YES)
// your below line asking the user to every document to save or close. In my above line save the document without user knowledge. which is best you can use it.
//myDocument.close(SaveOptions.ASK)
}
thx,
csm_phil
Copy link to clipboard
Copied
Hi csm_phil,
Thanks for your immediate reponse...
Problem is using the same variable throught the script. I think thats why the problem occur.
Now i change the variable name in Book Contents ('i' change into 'm'). Its working fine. Open and close all the book documents.
Again Thanks a lot for you, Hans and ALL.
Thanks
Beginner
Copy link to clipboard
Copied
Hello BEGGINER_X,
You always keep in mind, to select the choice of quesetions is "Answered" or "Helpfull Answer", otherwise the thread is still open, please this is important all the user, because the people go and watch the thread is waste of time. Because the thread is not answered?
Do the need full.
thx,
csm_phil.