Quantcast
Channel: Adobe Community : Popular Discussions - InDesign Scripting
Viewing all articles
Browse latest Browse all 15932

Continuing from a script error.

$
0
0

This has been a very frustrating problem to solve. We create technical documentation for industrial equipment. With each machine, we ship a physical manual and a CD with an inveractive PDF.

 

For physical manual, we need to strip out the interactivity color formatting so the print version looks correct; i.e. the blacks are truly black and some black pixilated version of dark blue.

 

I was looking for a script that would search and replace character styles so that I didn't have to do in manually, document by document.

 

Vandy88 provided me with this nifty scrip which works like a charm:

 

myBookFile = File.openDialog("Choose the BOOK File", "INDB:*.indb", false);

var myDoc=[];

if(myBookFile != null){  

    app.open(File(myBookFile.fullName.toString()));

    var myBook = app.activeBook

    for(var n=0; n < myBook.bookContents.length; n++)

    {

        myDoc[n] = app.open(File(myBook.bookContents[n].fullName.toString()));

        //--- cross referece style 1

        app.findGrepPreferences = app.changeGrepPreferences = null;

        app.findGrepPreferences.appliedCharacterStyle = "crossreference1";

        app.changeGrepPreferences.appliedCharacterStyle = "BoldUnderline";

        app.activeDocument.changeGrep();

        app.findGrepPreferences = app.changeGrepPreferences = null;

        //--- cross referece style 2

        app.findGrepPreferences = app.changeGrepPreferences = null;

        app.findGrepPreferences.appliedCharacterStyle = "crossreference2";

        app.changeGrepPreferences.appliedCharacterStyle = "BoldUnderline";

        app.activeDocument.changeGrep();

        app.findGrepPreferences = app.changeGrepPreferences = null;

    }

}

else{

    alert("Please select the book file properly !!!");

}

 

Now, here's my problem: Our books contain not only the chapter files, but also the Cover; TOC, Parts Lists, Schematics, and Index. Not all of these documents have the same character styles in use, as some of them, such as the Cover, TOC, Parts List, and Schematics, do not have cross-references. As nice as this script is, as soon as it enounters a file that does not have the character style it is looking for, it stops.

 

What I need is a why to catch this error, tell it to ignore the document and move on to the next.

 

I have expermented with Try/Catch but with no success. Cannot figure out what code to put in Catch to make it keep going or re-cycle. Even tried: Catch (e) {n=n+1} to no avail.

 

Was wondering if there is some Catch code I haven't firgured out, or if I need to do some sort of an if/else statement that makes sure the first character style exists in the document, and then, if is not, tells the script to skip that document and move on the next. Otherwise, I'll have to create a custom book with only the documents I know have the styles. Not a difficult chore, but it would be best if I could have a block of code that would deal with the original book.

 

Much thanks to Vandy88 for the original code and I would be very greatful to anyone who can help me figure out this problem.


Viewing all articles
Browse latest Browse all 15932

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>