Quantcast
Channel: Adobe Community : Popular Discussions - Illustrator Scripting
Viewing all articles
Browse latest Browse all 12845

batch script quits after one file

$
0
0

Hello Everyone! I'm having a bit of trouble getting this script file to batch correctly.

 

The script will open all pdf files from the user specified folder. Then it's supposed to open the first file and check all objects for specific colours (which are die lines) and change it to a specific spot colour. Now the script works perfectly if I run the script on one file. Now that I've tried to batch the code to execute on each file, it seems to fail after the first one.

 

I can't think of what would be causing this to happen. Please help!

 

Below is the code:

 

// Main Code [Execution of script begins here]
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var sourceFolder, files, fileType, sourceDoc, targetFile, pdfSaveOpts;


// Select the source folder.
sourceFolder = Folder.selectDialog( 'Select the folder with your PDFs you wish to batch');
// If a valid folder is selected
if ( sourceFolder != null )
{
    files = new Array();    fileType = "*.pdf"; //prompt( 'Select type of Illustrator files to you want to process. Eg: *.ai', ' ' );    // Get all files matching the pattern    files = sourceFolder.getFiles( fileType );    if ( files.length > 0 )    {        destFolder = sourceFolder;        alert(files.length);        for ( i = 0; i < files.length; i++)        {           sourceDoc = app.open(files[i]); // returns the document object           var docRef = sourceDoc;           //$.writeln(sourceDoc);           //$.writeln(i);           with (docRef) {             dieCutFind(docRef);             //var pdfSaveOptions = new PDFSaveOptions();             //sourceDoc.saveAs (destFolder ,  pdfSaveOptions);             //sourceDoc.close();         }
 }    }    else    {        alert( 'No matching files found' );    }

}
//////////////////////////////////////////////////////////////////////////
function dieCutFind(docRef){
    //'use strict';    var atomicBlackExists = "no";    var atomicRedExists = "no";    var redExists = "no";    var blueExists = "no";    var pinkExists = "no";    var orangeExists = "no";    //var doc = docRef;    var  doc = app.activeDocument;    if ( doc.pathItems.length > 0 ) {    thePaths = doc.pathItems;    numPaths = thePaths.length;        for ( i = 0; i < doc.pathItems.length; i++ ) {            pathArt = doc.pathItems[i];            var fillColor = pathArt.fillColor            var red = pathArt.strokeColor.red;            var green = pathArt.strokeColor.green;            var blue = pathArt.strokeColor.blue;            if(red !==undefined || green !==undefined || blue !==undefined){                if (fillColor !== undefined){                    if ( pathArt.parent.typename != "CompoundPathItem" && red== 201 && green == 11 && blue == 6) {                        //Atomic Red                        AtomicRed();                        pathArt.selected = true;                        pathArt.strokeColor = app.activeDocument.swatches.getByName("Atomic Red GCS-293").color;                        pathArt.selected = false;                    }                }            }        }    }
///////////////////////////////////////////////////////////////////////////    function AtomicRed() {        if (atomicRedExists !== "yes"){            atomicRedExists = "yes";            var doc = app.activeDocument;            // Create the new spot            var newSpot = doc.spots.add();            // Define the new color value            var newColor = new CMYKColor();            newColor.cyan = 14.29;            newColor.magenta = 100;            newColor.yellow = 100;            newColor.black = 5.01;            // of the new Spot's color. The spot color can then            // be applied to an art item like any other color.            newSpot.name = "Atomic Red GCS-293";            newSpot.colorType = ColorModel.SPOT;            newSpot.color = newColor;            var newSpotColor = new SpotColor();            newSpotColor.spot = newSpot;        }    };
};

Viewing all articles
Browse latest Browse all 12845

Trending Articles



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