Hi,
could you please help me to edit this script so it can only look for page items("Date", "Time", "Version", "Ops Component Code") in one specific layer named "Legend" insted of all layers?
/********************************************************** ADOBE SYSTEMS INCORPORATED Copyright 2005-2006 Adobe Systems Incorporated All Rights Reserved NOTICE: Adobe permits you to use, modify, and distribute this file in accordance with the terms of the Adobe license agreement accompanying it. If you have received this file from a source other than Adobe, then your use, modification, or distribution of it requires the prior written permission of Adobe. *********************************************************/ /** Saves every document open in Illustrator as a PDF file in a user specified folder. */ // Main Code [Execution of script begins here] try { // uncomment to suppress Illustrator warning dialogs // app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS; if (app.documents.length > 0 ) { var options, i, sourceDoc, targetFile,; // Get the PDF options to be used options = this.getOptions(); if (options != null) { sourceDoc = app.activeDocument; // returns the document object var fullName = sourceDoc.fullName; fullName = fullName.toString(); var destFolder = fullName.slice(0,fullName.lastIndexOf("/")) var dateFound = false; var versionFromName = fullName.slice(fullName.lastIndexOf("-")+1, fullName.lastIndexOf("_")); var opsFromName = fullName.slice(fullName.lastIndexOf("/")+1, fullName.lastIndexOf("-")); var theVersionNumber = null; var dateField = null; var timeField = null; var opsVersionCode = null; for(i=0; i<sourceDoc.pageItems.length;i++) { if (sourceDoc.pageItems[i].note == "Date") { dateField = sourceDoc.pageItems[i]; } if (sourceDoc.pageItems[i].note == "Time") { timeField = sourceDoc.pageItems[i]; } if (sourceDoc.pageItems[i].note == "Version") { theVersionNumber = sourceDoc.pageItems[i].contents; } if (sourceDoc.pageItems[i].note == "Ops Component Code") { opsVersionCode = sourceDoc.pageItems[i].contents; } } if (theVersionNumber == versionFromName) { if (opsVersionCode == opsFromName) { if (dateField == null) { alert('No tagged date field found. Tag field and try again.') } else { dateField.contents = TodayDate() timeField.contents = TodayTime() OLtargetFile = this.getTargetFile(sourceDoc.name, '.pdf', destFolder); sourceDoc.saveAs( OLtargetFile, options) // alert( 'Documents saved as PDF' ); } } else { alert('Ops component code in boiler does not match file name or is not tagged. Please correct and try again.') } } else { alert('Version number in boiler does not match file name or is not tagged. Please correct and try again.') } } else { alert('User aborted') } } else { throw new Error('There are no document open!'); } } catch(e) { alert( e.message, "Script Alert", true); } /** Returns the options to be used for the generated files. @return PDFSaveOptions object */ function getOptions() { // Create the required options object var options = new PDFSaveOptions(); // See PDFSaveOptions in the JavaScript Reference for available options options.pDFPreset = "AZ" // For example, uncomment to set the compatibility of the generated pdf to Acrobat 7 (PDF 1.6) // options.compatibility = PDFCompatibility.ACROBAT7; // For example, uncomment to view the pdfs in Acrobat after conversion // options.viewAfterSaving = true; return options; } function abortFunction(){ modUI = null; dlg.hide(); return null; } /** Returns the file to save or export the document into. @param docName the name of the document @param ext the extension the file extension to be applied @param destFolder the output folder @return File object */ function getTargetFile(docName, ext, destFolder) { var newName = ""; // if name has no dot (and hence no extension), // just append the extension if (docName.indexOf('.') < 0) { newName = docName + ext; } else { var dot = docName.lastIndexOf('.'); newName += docName.substring(0, dot); newName += ext; } // Create the file object to save to var myFile = new File( destFolder + '/' + newName ); // Preflight access rights if (myFile.open("w")) { myFile.close(); } else { throw new Error('Access is denied'); } return myFile; } function TodayDate(){ var Dateformat = "dd mm yyyy"; nameMonths = true; var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var Today = new Date(); var Day = Today.getDate(); if(nameMonths == true){ var Month = monthNames[Today.getMonth()]; } else { var Month = Today.getMonth() + 1;} var Year = Today.getYear(); var PreMon = ((Month < 10) ? "0" : ""); var PreDay = ((Day < 10) ? "0" : ""); var Hour = Today.getHours(); var Min = Today.getMinutes(); var Sec = Today.getSeconds(); if(Year < 999) Year += 1900; var theDate = Dateformat.replace(/dd/,PreDay+Day); theDate = theDate.replace(/mm/,PreMon+Month); theDate = theDate.replace(/d/,Day); //theDate = theDate.replace(/m/,Month); theDate = theDate.replace(/yyyy/,Year); theDate = theDate.replace(/yy/,Year.toString().substr(2,2)); if(Hour==0){ Hour = "12"; theDate = theDate.replace(/XX/,"AM"); }else if(Hour>12){ Hour = (Hour-12); theDate = theDate.replace(/XX/,"PM"); }else{ theDate = theDate.replace(/XX/,"AM"); } var preSec = ((Sec < 10) ? "0" : ""); var preHour = ((Hour < 10) ? "0" : ""); var preMin = ((Min < 10) ? "0" : ""); theDate = theDate.replace(/hr/,preHour+Hour); theDate = theDate.replace(/Mn/,preMin+Min); theDate = theDate.replace(/sc/,preSec+Sec); return theDate; } function TodayTime(){ var Dateformat = "hr:Mn"; nameMonths = false; var monthNames = ["January","February","March","April","May","June","July","August","September","October","November","December"]; var Today = new Date(); var Day = Today.getDate(); if(nameMonths == true){ var Month = monthNames[Today.getMonth()]; } else { var Month = Today.getMonth() + 1;} var Year = Today.getYear(); var PreMon = "";//((Month < 10) ? "0" : ""); var PreDay = ((Day < 10) ? "0" : ""); var Hour = Today.getHours(); var Min = Today.getMinutes(); var Sec = Today.getSeconds(); if(Year < 999) Year += 1900; var theDate = Dateformat.replace(/dd/,PreDay+Day); theDate = theDate.replace(/mm/,PreMon+Month); theDate = theDate.replace(/d/,Day); theDate = theDate.replace(/m/,Month); theDate = theDate.replace(/yyyy/,Year); theDate = theDate.replace(/yy/,Year.toString().substr(2,2)); if(Hour==0){ Hour = "12"; theDate = theDate.replace(/XX/); }else{ theDate = theDate.replace(/XX/); } var preSec = ((Sec < 10) ? "0" : ""); var preHour = ((Hour < 10) ? "0" : ""); var preMin = ((Min < 10) ? "0" : ""); theDate = theDate.replace(/hr/,preHour+Hour); theDate = theDate.replace(/Mn/,preMin+Min); theDate = theDate.replace(/sc/,preSec+Sec); return theDate; }