2 Replies Latest reply on Feb 20, 2015 2:59 AM by Peter Kahrel

    Script to open all cross-referenced book files?

    Research Mannikins

      I produce a 544 page product catalog that is broken into 33 files within a Book file. I have hundreds of cross-references referencing items throughout the book. In order to keep InDesign from bogging down to a snail's pace when I work on a file, I have to open all the associated cross referenced files as well. Is there a script that would open all cross referenced book files, rather than manually opening a dozen or more other files each time?

       

      This constant live updating of cross-references, that cannot be turned off, continues to be a huge performance shortcoming of InDesign, even in CC2014.

       

      Kevin Shilts

      Lebanon, Oregon

      InDesign user since 1999

        • 1. Re: Script to open all cross-referenced book files?
          Peter Spier Most Valuable Participant (Moderator)

          Moved to the scripting forum...

          • 2. Re: Script to open all cross-referenced book files?
            Peter Kahrel Adobe Community Professional & MVP

            Here is a script I use to open all book files and close them all with or without saving. The script checks if there's a book open, then shows a small window in which you select what you want to do.

             

            Peter

             

             

            book_stuff ();
            
            function book_stuff ()
            {
                var book = get_book ();
                switch (do_stuff())
                {
                    case "open_docs" : open_bookdocuments(book); break;
                    case "close_docs_no_save": close_book_without_saving (book); break;
                    case "save_and_close_docs": save_and_close_bookdocuments (book); break;
                }
            }
            
            
            function save_and_close_bookdocuments (book)
            {
                var chapters = book.bookContents.everyItem().name;
                var progress = progressBar ("Saving and closing book contents...", chapters.length);
                progress.show();
                for (var i = chapters.length-1; i >= 0; i--)
                {
                    progress.bar.value+=1;
                    app.documents.item(chapters[i]).save (chapters[i].fullName);
                    app.documents.item(chapters[i]).close();
                }
                progress.close();
            }
            
            
            function open_bookdocuments (book)
            {
                var chapters = book.bookContents.everyItem().getElements();
                var progress = progressBar ("Opening book contents...", chapters.length);
                progress.show();
                for (var i = 0; i < chapters.length; i++)
                {
                    progress.bar.value+=1;
                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.neverInteract;
                    app.open(chapters[i].fullName);
                    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
                }
                progress.close();
            }
            
            
            function close_book_without_saving (book)
            {
                var chapters = book.bookContents.everyItem().name;
                var progress = progressBar ("Closing book contents...", chapters.length);
                progress.show();
                for (var i = chapters.length-1; i>-1; i--)
                {
                    progress.bar.value += 1;
                    app.documents.item(chapters[i]).close(SaveOptions.no);
                }
                progress.close();
            }
            
            
            
            function progressBar (title, stop)
            {
                var w = new Window ("palette", title, undefined, {resizeable:true,closeButton:false});
                w.bar = w.add ("progressbar", [0,0,300,20], 0, stop);
                return w;
            }
            
            
            function get_book ()
            {
                switch (app.books.length)
                {
                    case 0: alert ("Please open a book."); exit ();
                    case 1: return app.books[0];
                    default: return pick_book ();
                }
            }
            
            
            function pick_book ()
            {
                var w = new Window ("dialog", "Select a book");
                w.alignChildren = "right";
                var g = w.add ("group");
                    var list = g.add ("listbox", undefined, app.books.everyItem().name);
                    list.minimumSize.width = 250;
                    list.selection = 0;
                var b = w.add ("group");
                    b.add ("button", undefined, "OK", {name: "ok"})
                    b.add ("button", undefined, "Cancel", {name: "cancel"})
                if (w.show () == 1)
                    return app.books.item(list.selection.text);
                else
                    exit ();
            }
            
            
            function do_stuff ()
            {
                var w = new Window("dialog");
                    var panel = w.add ("panel {alignChildren: 'left'}");
                        panel.add ("radiobutton {text: 'Open all book documents'}");
                        panel.add ("radiobutton {text: 'Close all book documents without saving'}");
                        panel.add ("radiobutton {text: 'Save all book documents and close them'}");
            
                    var buttons = w.add ("group {alignment: 'right'}");
                        buttons.add ("button {text: 'OK'}");
                        buttons.add ("button {text: 'Cancel'}");
                        
                    if (app.documents.length == 0) {
                        panel.children[0].value = true;
                    } else {
                        panel.children[1].value = true;
                    }
                    
                        
                    if (w.show() == 1)
                    {
                        var n = 0;
                        while (!panel.children[n].value) ++n;
                        return ["open_docs", "close_docs_no_save", "save_and_close_docs"][n];
                    }
                    exit();
            }