In batch mode, actions from the data source can be applied to a number of input documents.
The plugin Batch only provides the user interface and is optional.
Using the panel Batch the batch operation can be configured and started or stopped:
Batch processing processes all documents from inside the input folder ('Hotfolder'). Processing is performed in alphabetical order and includes the following steps:
The second step is decisive here, in which all processing of the input document must take place.
Batch actions are always cScripts with ClassID 22. These are stored as usual in the data source (e.g. actions.xml in case of XML offline).
The following global variables are defined in the script during the execution of a batch action on an input file:
Variable | Type | Description |
gObjectPath | char * | File path of the input file before moving it to the XCache. This file does not exist anymore at this point, because it has already been moved to the XCache! |
gInFile | char * | File path of the input file in the XCache. This is the current file you are working on! |
gSourcefolder | char * | The designated input folder |
gDestfolder | char * | The designated output folder |
All variables are only provided as global variables in the cScript - for a correct processing like e.g. opening, changing and saving the input document into the output folder you are responsible yourself!
Since the document is not opened automatically by the batch mode (e.g. other input documents than Illustrator files could be processed), variables like gDocument are not defined here!
Here is an example for processing a document in batch mode and saving several variants:
//This script creates a language variant of a document by setting the //gLanguage attribute on the document itself, loading all placeholders //and saving the document under a new name with the language as suffix. #include "internal/types.h" #include "internal/products.h" int main() { String languageVariants = string::alloc("deDE;enEN"); String languageVariant = string::alloc(); int languageVariantsCount = string::token_count(languageVariants, ';'); ItemList allFrames = 0; int framesCount = 0; int i = 0; int j = 0; int k = 0; ItemRef frame = item::alloc(); Image preview = 0; String outPreviewPath = string::alloc(); ItemRef doc = 0; String docName = string::alloc(); String docNameShort = string::alloc(); String outName = string::alloc(); String outPath = string::alloc(); //get the products from the product pool panel which are watched ProductList products = productlist::get("watched"); int productsCount = productlist::length(products); Product currentProduct = 0; int productID1 = 0; int productID2 = 0; int productID3 = 0; String productStringID = string::alloc(); String productName = string::alloc(); if (!productsCount) { showmessage("You need to set some products watched in the product pool!"); batch::stop(); return 0; } //Make sure we only handle .ai input files wlog("", "Begin batch job for input file '%s'", gInFile); file::extender(inFileExtension, gInFile); if (string::compare(inFileExtension, "ai") != 0) { wlog("", "Skipping input file '%s' - not an Illustrator file.\n", gInFile); return 0; } //open the base document and prepare it doc = document::open(gInFile); if (!doc) { return 0; } document::select(doc); document::name(docName); wlog("", "Document name is:%s\n", docName); if (!string::length(docName)) { //no document opened return 0; } //iterate over all language variants for (k = 0; k < languageVariantsCount; k++) { string::set(languageVariant, string::token(languageVariants, ';', k)); //now iterate over all products for (j = 0; j < productsCount; j++) { //fetch the frames from the document allFrames = itemlist::allframes_of_doc(doc); //set the language for the placeholders to load xml::set_document_attribute(doc, "gLanguage", languageVariant); //fetch the product ids so we can link all frames to this product currentProduct = productlist::get_nth(products, j); productID1 = product::get(currentProduct, kID); productID2 = product::get(currentProduct, kID2); productID3 = product::get(currentProduct, kID3); string::set(productStringID, product::gets(currentProduct, kStringID)); string::set(productName, product::gets(currentProduct, kRow1)); wlog(", "Linking all frames to product %d, %d, %d, '%s' - '%s'\n", productID1, productID2, productID3, productStringID, productName); //calculate the output name string::set(outName, "%s_%s_%s", file::shortname(docNameShort, docName), productName, languageVariant); wlog("", "Output name is:%s\n", outName); framesCount = itemlist::length(allFrames); wlog("", "Linking and loading %d frames\n", framesCount); for (i = 0; i < framesCount; i++) { itemlist::get(allFrames, frame, i); //link the frame to our current product... placeholder::link2(frame, 0, productID1, productID2, productID3, productStringID); //...and load the frame placeholder::load(frame); } string::set(outPath, "%s/%s.ai", gDestfolder, outName); string::set(outPreviewPath, "%s/%s.png", gDestfolder, outName); wlog("", "Creating preview at %s\n", outPreviewPath); preview = image::snapshot_page(0, 1, kOriginalSize, "PNG"); image::save(preview, outPreviewPath, 1); document::saveas(doc, outPath); } } if (doc) document::close(doc); } return 0; }
There are several cScript functions available for driving the batch processing:
The panel has the classID 405