Im Batch Betrieb können Aktionen der Datenquelle auf eine Reihe von Eingabedokumenten angewendet werden.
Das Plugin Batch stellt lediglich die Benutzeroberfläche zur Verfügung und ist optional.
Über die Palette Batch kann der Batchbetrieb konfiguriert und gestartet oder gestoppt werden:
Die Batchverarbeitung bearbeitet alle Dokumente aus dem Eingabeordner ('Hotfolder'). Die Verarbeitung findet dabei in alphabetischer Reihenfolge statt und beinhaltet die folgenden Schritte:
Entscheidend ist hier der zweite Schritt, in dem sämtliche Bearbeitungen des Eingabedokumentes erfolgen müssen.
Batchaktionen sind immer cScripte mit der ClassID 22. Diese werden wie gewohnt in der Datenquelle (z.B. actions.xml im Falle von XML Offline) hinterlegt.
Während der Ausführung einer Batchaktion auf einer Eingabedatei sind im Script folgende Globale Variablen definiert:
Variable | Typ | Beschreibung |
gObjectPath | char * | Dateipfad der Eingabedatei vor dem Verschieben in den XCache. Diese Datei existiert zu diesem Zeitpunkt nicht mehr, da Sie bereits in den XCache verschoben wurde! |
gInFile | char * | Dateipfad der Eingabedatei im XCache. Dies ist die aktuelle Datei auf der gearbeitet wird! |
gSourcefolder | char * | Der eingestellte Eingabeordner |
gDestfolder | char * | Der eingestelle Ausgabeordner |
Alle Variablen werden dabei lediglich als globale Variable im cScript zur Verfügung gestellt - für eine korrekt Verarbeitung wie .z.B. Öffnen, Verändern und Sichern des Eingabedokumentes in den Ausgabeordner sind Sie selbst verantwortlich!
Da dass Dokument nicht selbstständig vom Batchbetrieb geöffnet wird (es könnten ja z.B. auch andere Eingabedokumente als Illustrator Dateien verarbeitet werden), sind Variablen wie gDocument hier nicht definiert!
Hier ein Beispiel zur Bearbeitung eines Dokumentes im Batchbetrieb und sichern mehrerer Varianten:
//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; }
Über cScript werden Befehle zur Verfügung gestellt um den Batchbetrieb zu steuern:
Die Palette hat die ClassID 405