Here's my code in case this gives a better understanding of my problem. In line 22 I thought I would be getting the correct print area from that point on because the artboard is always the correct size, but I am not. I made sure to define the inklist afterwards as well. I have alert messages to test which colors it can sense and I have learned that colors outside of the 8.5 by 11 area and within the correct 17 20 print area are not enabled on the ink list.
/*
IDEAS:
IF INK LIST CANT BE FIXED, COMPARE LIST BEFORE AND AFTER PRINTED. IF DIFFERENT, ALERT THE USER.
*/
app.coordinateSystem = CoordinateSystem.ARTBOARDCOORDINATESYSTEM;
printPostScript();
function printPostScript() {
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
var docPath, docRef, inFolder, opts, psPath;
jobOpts = new PrintJobOptions();
//Should work right? Not till it prints, doh!!!!
jobOpts.printArea = PrintingBounds.ARTBOARDBOUNDS;
opts = new PrintOptions();
//opts.printPreset = 'Print Preset 1';
opts.jobOptions = jobOpts;
opts.PPDName = 'AdobePdf';
opts.printerName= 'Adobe PostScript File';
sepOpts = new PrintColorSeparationOptions();
sepOpts.colorSeparationMode = PrintColorSeparationMode.HOSTBASEDSEPARATION;
opts.colorSeparationOptions = sepOpts;
var cmyk = false;
docRef = app.activeDocument;
//hoping the doc would be reading 17 by 20 print area at this point....not successful yet.
sepOpts.inkList = docRef.inkList;
for (i = 0; i < 4; i ++) {
if (sepOpts.inkList.inkInfo.printingStatus == InkPrintStatus.ENABLEINK) {
cmyk = true;
}
}
if (cmyk == false) {
var numbers = ' ';
var colorsOnScreen = [];
var x = 0;
for (j= docRef.groupItems.length-1; j > -1; j--) {
if (docRef.groupItems .name == 'numGroup' && Math.round(docRef.groupItems .left) == 639 && Math.round(docRef.groupItems .top) == -21) {
var numGroup = docRef.groupItems ;
for (k = numGroup.textFrames.length - 1; k > -1; k --) {
if (numGroup.textFrames .textRange.characterAttributes.fillColor == '[SpotColor]'){
//put numbers at end of file name
numbers = numbers + ' ' + String(numGroup.textFrames .contents)
//cross reference this with enabled colors, disable colors that don't match....background color for one of them
colorsOnScreen = numGroup.textFrames .textRange.characterAttributes.fillColor.spot.name;
x++
}
}
}
}
var docName = docRef.name.replace( /.ai$/, '' );
psPath = docName.replace(/\./g , "_" );
// on garnment color and number screens
// file name preview
//gets rid of content between paranthesis
var updatedPath = psPath.replace(/ *\([^)]*\) */g, "");
var myWindow = new Window ("dialog", "Post Script Generator");
myWindow.orientation = "column";
myWindow.alignChildren = "left";
var colorGroup = myWindow.add("group");
colorGroup.orientation = "column";
colorGroup.alignChildren = "left";
var colorPanels= [];
u=0;
var inkEn = [];
c=0;
var gc = 'white';
for (t = 4; t < sepOpts.inkList.length; t ++) {
alert(sepOpts.inkList .name)
alert(sepOpts.inkList .inkInfo.printingStatus)
if (sepOpts.inkList .inkInfo.printingStatus == InkPrintStatus.ENABLEINK) {
inkEn = sepOpts.inkList ;
c++;
colorPanels = colorGroup.add("group");
colorPanels.alignChildren = "left";
colorPanels.add ("statictext", [0, 0, 100, 12], sepOpts.inkList .name);
var yes = colorPanels.add("checkbox", undefined, 'Print');
colorPanels.add("checkbox", undefined, 'Halftone');
for (l=0; l < colorsOnScreen.length; l++) {
if (sepOpts.inkList .name == colorsOnScreen ) {
yes.value = true;
}
}
u++;
if (yes.value != true) {
// the garment color is the one we are not outputting. In rare instances of not outputting more than one color, it's a guess.
gc = sepOpts.inkList .name;
}
}
}
var colorCheck = gc.indexOf ('PMS');
var spotCheck = gc.substr (0, 4);
if (colorCheck > 1) {
gc = gc.substr(0,colorCheck - 1);
}
else if (spotCheck == 'SPOT') {
gc = gc.substr(5,gc.length);
}
var nameGroup = myWindow.add("group");
nameGroup.orientation = "row";
nameGroup.add ("statictext", undefined, "File:");
// put file name preview here
var myText = nameGroup.add ("edittext", undefined, updatedPath);
myText.characters = 80;
myText.active = false;
nameGroup.add ("statictext", undefined, "Garment:");
var myText2 = nameGroup.add ("edittext", undefined, gc);
myText2.characters = 20;
myText2.active = true;
var okButton = nameGroup.add ("button", undefined, "OK");
nameGroup.add ("button", undefined, "Cancel");
if (myWindow.show () == 1) {
for(v=0; v < colorPanels.length; v ++) {
if (colorPanels .children[1].value == false) {
//turn off print
for (m = 0; m < inkEn.length; m ++) {
if (inkEn .name == colorPanels .children[0].text) {
inkEn .inkInfo.printingStatus = InkPrintStatus.DISABLEINK;
}
}
}
else {
//check half tones
if (colorPanels .children[2].value == true) {
for (m = 0; m < inkEn.length; m ++) {
if (inkEn .name == colorPanels .children[0].text) {
inkEn .inkInfo.angle = 30;
inkEn .inkInfo.frequency = 42;
}
}
}
}
};
// add garment color to the end of file name, delete everything after parenthesis, turn periods to hyphens or underscore
docPath = decodeURI( '//fileserver/SpoolFolder/' + myText.text + ' on ' + myText2.text + ' ' + numbers + '.ps' );
docPath2 = decodeURI( '//fileserver/ImageFolder/' + myText.text + ' on ' + myText2.text + ' ' + numbers + '.ps' );
// inkEn
jobOpts.file = File( docPath );
app.activeDocument.print( opts );
jobOpts.file = File( docPath2 );
app.activeDocument.print( opts );
}
}
else {
alert('CMYK COLOR DETECTED','Crap');
}
};
So yea, for this to work correctly I would need to have the right print area before it prints. Through UI you can select a print preset and hit 'done' instead of print, been trying to find a way to do that through script, have not yet. Send Keys is always an option but that leaves room for error. Tried looking for a way that Illustrator always has a print preset active no matter what file you open, haven't found that either. An alternative would be to compare the inklist before and after print has taken place and then alert the user if it's different, but that would still create some work by having to go and delete files, and I want as little work as possible lol. Guess I could randomly print something at the beginning and then define the inklist but that would be poopy having to print extra files. So close yet so far. I'm done for the day, take care everyone!
... View more