Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Pause or Wait Between Commands...

Explorer ,
Dec 14, 2016 Dec 14, 2016

The below is a portion of a larger script I have... What I'm wanting to do is place a Pause/Wait/Sleep (whichever is appropriate) command to wait on the item to finish printing before proceeding to the next section...

I've added the sleep function... but it doesn't appear to be working or is not understanding what I'm wanting it to do...

Any Ideas

//Print

var storeUserInteract = userInteractionLevel;

var d                 = activeDocument;

var jbOpts            = new PrintJobOptions();

var opts              = new PrintOptions();

opts.printPreset      = "JEFF_HP";

opts.jobOptions       = jbOpts;

userInteractionLevel  = UserInteractionLevel.DONTDISPLAYALERTS;

d.print(opts);

userInteractionLevel = storeUserInteract;

$.sleep (10000);

//Through Cut Backward

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     sendThruCutBackward();

}

wrapper();

TOPICS
Scripting
4.5K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Mentor , Jan 11, 2017 Jan 11, 2017

Ok. I thought you meant that " - Proof" was somehow being added to the beginning of the string which just didn't make any sense.

So your resulting filename is "my_placed_image.pdf"?

try this:

 

saveAsPdf(

     '~/Desktop/Illustrator Hot Folder/Reveal Zund Marks/OUT',

     activeDocument.placedItems[0].file.name,

     'Dynagraphics PDF - Flat - Layers'

);

function saveAsPdf(targFoldPath, targFileName, pdfPresName)

{

     var destFolder = new Folder (targFoldPath);

     var pdfOpts = new PDFSaveOptions();

   

...
Translate
Adobe
Engaged ,
Dec 14, 2016 Dec 14, 2016

I think you don't need $.sleep in this case. I think in this snippet all actions will performed in sequence, after the previous steps will completed.

New for exemple, this code is executed sequentially:

//@target illustrator

// print to first file

var pres = 'JEFF_HP';

prnt('test1', pres);

// any another actions

wrapper();

redraw(); // if you whant to redraw the screen

// print to second file or make another actions

prnt('test2', pres);

function wrapper(){ 

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    var artLayer = layers["Artwork"];

    var thruCutLayer = layers["Through Cut"];  

    function bringThruCutForward()     {

        thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

    }  

    function sendThruCutBackward()     {

        thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

    }

    sendThruCutBackward();

}

function prnt(fileName, printPresetName){

    var storeUserInteract = userInteractionLevel; 

    var d                 = activeDocument; 

    var filePath          = '/d/' + fileName + '.ps'

    var jbOpts            = new PrintJobOptions(); 

    var opts              = new PrintOptions(); 

    opts.printPreset      = "printPresetName"; 

    opts.jobOptions       = jbOpts; 

    jbOpts.file           = new File(filePath); 

    userInteractionLevel  = UserInteractionLevel.DONTDISPLAYALERTS; 

    d.print(opts); 

    userInteractionLevel = storeUserInteract;  

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2016 Dec 15, 2016

o-marat

Thanks for replying but this is not accomplishing what I need... or should i say it's not working... It's hanging up on line 35...

The previous code I had was working great with the exception it was advancing before the print option was done....

Any further ideas on what to do..????

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 15, 2016 Dec 15, 2016

I think I made an error in my code in a line 31

Replace this:

opts.printPreset = "printPresetName";

to that

opts.printPreset = printPresetName;

​and my code must work correctly

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2016 Dec 15, 2016

Here is my full script... I've marked the areas that I'm having trouble with... Any help is greatly appreciated...

**********************************

#target illustrator

var theFile = File('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/ZTemplate/Zund Setup.ait');

app.open(theFile);

//Place New Image 

var fo = Folder ( '~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/IN' ); 

var files = fo.getFiles ( /* you may want to use a filter function here. See doc */ ); 

var file, newimage; 

   

while ( file = files.pop() ) { 

var docRef = app.activeDocument; 

  newimage = docRef.placedItems.add();  

  newimage.file = file;  

  newimage.position = [200,-300]; 

//set artboard size to image size

var docRef = app.activeDocument;

var artboards = docRef.artboards;

var theImg = docRef.placedItems[0];

theImg.left = 0;

theImg.top = 0;

artboards[0].artboardRect = [0,0,theImg.width,-(theImg.height)]

//Fit artboard To window

app.executeMenuCommand ('fitall');

// Get Canvas Size and Add Through Cut Layer

function container()

{

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    var swatches = docRef.swatches;

    var artboards = docRef.artboards;

    var artLay, cutLay;

    var bleed = 18;

    var theImg = docRef.placedItems[0];

    theImg.left = 0;

    theImg.top = 0;

    var docSize = [theImg.width,theImg.height];

    artboards[0].artboardRect = [0,0,docSize[0],-(docSize[1])];

    function initLayers()

    {

        artLay = layers.add();

        artLay.name = "Artwork";

        theImg.moveToBeginning(artLay);

        cutLay = layers.add();

        cutLay.name = "Through Cut";

    }

    function addThroughCut()

    {

        var cutLine = cutLay.pathItems.rectangle(-(bleed),bleed,docSize[0]-(bleed*2),docSize[1]-(bleed*2));

        cutLine.filled = false;

        cutLine.strokeColor = swatches["Through Cut"].color;

    }

initLayers();

    addThroughCut();

layers["Layer 1"].remove();

      

}

container();

//Through Cut Forward

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     bringThruCutForward();

}

wrapper();

//Print

var storeUserInteract = userInteractionLevel;

var d                 = activeDocument;

var jbOpts            = new PrintJobOptions();

var opts              = new PrintOptions();

opts.printPreset      = "JEFF_HP";

opts.jobOptions       = jbOpts;

userInteractionLevel  = UserInteractionLevel.DONTDISPLAYALERTS;

d.print(opts);

userInteractionLevel = storeUserInteract;

///I If I just run the script to this point... Everything is perfect... It opens my template... Add's my Cut Lines, Places them on top and Prints Perfect...

/// However when I start adding the additional pieces below... it acts as if it's not seeing some of the commands or running through them like they don't exist

///Save as pdf... I added this step to Save a .pdf with the Cut line on top of the art working for proofing and attempted to add the word PROOF before the file name... However this step is not working or it doesn't save the word "Proof" at the beginning

try {

  if (app.documents.length > 0 ) {

  var destFolder = null;

  destFolder = Folder('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/OUT');

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

  options = this.getOptions();

            options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  for ( i = 0; i < app.documents.length; i++ ) {

      sourceDoc = app.documents;

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(Proof+app.activeDocument.placedItems[0].file.name, '.pdf', destFolder); /// This is the line I added "Proof+" to the name that's not working

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  //alert( 'Documents saved as PDF' );

  }

  }

  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();

    options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  return options;

}

function getTargetFile(docName, ext, destFolder) {

  var newName = "";

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName += docName.substring(0, dot);

  newName += ext;

  }

  var myFile = new File( destFolder + '/' + newName );

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

//Through Cut Backward... This moves my Cut layers behind the artwork

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     sendThruCutBackward();

}

wrapper();

///Save as pdf... This Saves my art with the Cutlines Behind the Artwork... This part is working ok...

try {

  if (app.documents.length > 0 ) {

  var destFolder = null;

  destFolder = Folder('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/OUT');

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

  options = this.getOptions();

            options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  for ( i = 0; i < app.documents.length; i++ ) {

      sourceDoc = app.documents;

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(app.activeDocument.placedItems[0].file.name, '.pdf', destFolder);

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  //alert( 'Documents saved as PDF' );

  }

  }

  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();

    options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  return options;

}

function getTargetFile(docName, ext, destFolder) {

  var newName = "";

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName += docName.substring(0, dot);

  newName += ext;

  }

  var myFile = new File( destFolder + '/' + newName );

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

//Close the open Document Command

app.documents[0].close(SaveOptions.DONOTSAVECHANGES)

//This line is set to clear the file out of the HotFolder when complete... Works great

var myFolder = Folder( '~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/IN' );

  var myFiles = myFolder.getFiles();

  for(var i=myFiles.length - 1; i > -1;  i--){

    myFiles.remove();

  }; ! !

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2016 Dec 15, 2016

o-marat​ Did you see my full code listed above... Wasn't sure if you could see what was going on there...

Also Silly-V​ & williamadowling​ Feel free to pipe in if possible...

Thanks for all your help...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 15, 2016 Dec 15, 2016

What is this: files.pop() ??

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Valorous Hero ,
Dec 15, 2016 Dec 15, 2016

file = files.pop() takes the last element of the 'files' array and puts it into the 'file' variable.

It's best to construct your own little snippets and that way you know what's going on in there exactly. You surely don't wanna use some code you know not what is inside, because in case many of your files end up having some problem, you'd want to be sure about what's happening to them via the scripts.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2016 Dec 15, 2016

I'm embarrassed to say... I don't know... I had asked for assistance in creating that part of the script to be able to place images from a Hot folder... and that was the script I got back... It does work successfully and does what I needed... but it's possible it's just extra Fluff ???

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 15, 2016 Dec 15, 2016

Thanks... but that part of this script is working perfectly... however there are other parts.. that i've marked that are not... was hoping someone could look it over and see why it's not working...I've bolded the type so it's easy to spot....

I've attached a copy below...

#target illustrator

var theFile = File('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/ZTemplate/Zund Setup.ait');

app.open(theFile);

//Place New Image 

var fo = Folder ( '~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/IN' ); 

var files = fo.getFiles ( /* you may want to use a filter function here. See doc */ ); 

var file, newimage; 

   

while ( file = files.pop() ) { 

var docRef = app.activeDocument; 

  newimage = docRef.placedItems.add();  

  newimage.file = file;  

  newimage.position = [200,-300]; 

//set artboard size to image size

var docRef = app.activeDocument;

var artboards = docRef.artboards;

var theImg = docRef.placedItems[0];

theImg.left = 0;

theImg.top = 0;

artboards[0].artboardRect = [0,0,theImg.width,-(theImg.height)]

//Fit artboard To window

app.executeMenuCommand ('fitall');

// Get Canvas Size and Add Through Cut Layer

function container()

{

    var docRef = app.activeDocument;

    var layers = docRef.layers;

    var swatches = docRef.swatches;

    var artboards = docRef.artboards;

    var artLay, cutLay;

    var bleed = 18;

    var theImg = docRef.placedItems[0];

    theImg.left = 0;

    theImg.top = 0;

    var docSize = [theImg.width,theImg.height];

    artboards[0].artboardRect = [0,0,docSize[0],-(docSize[1])];

    function initLayers()

    {

        artLay = layers.add();

        artLay.name = "Artwork";

        theImg.moveToBeginning(artLay);

        cutLay = layers.add();

        cutLay.name = "Through Cut";

    }

    function addThroughCut()

    {

        var cutLine = cutLay.pathItems.rectangle(-(bleed),bleed,docSize[0]-(bleed*2),docSize[1]-(bleed*2));

        cutLine.filled = false;

        cutLine.strokeColor = swatches["Through Cut"].color;

    }

initLayers();

    addThroughCut();

layers["Layer 1"].remove();

      

}

container();

//Through Cut Forward

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     bringThruCutForward();

}

wrapper();

//Print

var storeUserInteract = userInteractionLevel;

var d                 = activeDocument;

var jbOpts            = new PrintJobOptions();

var opts              = new PrintOptions();

opts.printPreset      = "JEFF_HP";

opts.jobOptions       = jbOpts;

userInteractionLevel  = UserInteractionLevel.DONTDISPLAYALERTS;

d.print(opts);

userInteractionLevel = storeUserInteract;

///I If I just run the script to this point... Everything is perfect... It opens my template... Add's my Cut Lines, Places them on top and Prints Perfect...

/// However when I start adding the additional pieces below... it acts as if it's not seeing some of the commands or running through them like they don't exist

///Save as pdf... I added this step to Save a .pdf with the Cut line on top of the art working for proofing and attempted to add the word PROOF before the file name... However this step is not working or it doesn't save the word "Proof" at the beginning

try {

  if (app.documents.length > 0 ) {

  var destFolder = null;

  destFolder = Folder('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/OUT');

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

  options = this.getOptions();

            options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  for ( i = 0; i < app.documents.length; i++ ) {

      sourceDoc = app.documents;

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(Proof+app.activeDocument.placedItems[0].file.name, '.pdf', destFolder); /// This is the line I added "Proof+" to the name that's not working

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  //alert( 'Documents saved as PDF' );

  }

  }

  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();

    options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  return options;

}

function getTargetFile(docName, ext, destFolder) {

  var newName = "";

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName += docName.substring(0, dot);

  newName += ext;

  }

  var myFile = new File( destFolder + '/' + newName );

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

//Through Cut Backward... This moves my Cut layers behind the artwork

function wrapper()

{

     var docRef = app.activeDocument;

     var layers = docRef.layers;

     var artLayer = layers["Artwork"];

     var thruCutLayer = layers["Through Cut"];

   

     function bringThruCutForward()

     {

          thruCutLayer.zOrder(ZOrderMethod.BRINGTOFRONT);

     }

     function sendThruCutBackward()

     {

          thruCutLayer.zOrder(ZOrderMethod.SENDTOBACK);

     }

     sendThruCutBackward();

}

wrapper();

///Save as pdf... This Saves my art with the Cutlines Behind the Artwork... This part is working ok...

try {

  if (app.documents.length > 0 ) {

  var destFolder = null;

  destFolder = Folder('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/OUT');

  if (destFolder != null) {

  var options, i, sourceDoc, targetFile;

  options = this.getOptions();

            options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  for ( i = 0; i < app.documents.length; i++ ) {

      sourceDoc = app.documents;

  // Get the file to save the document as pdf into

  targetFile = this.getTargetFile(app.activeDocument.placedItems[0].file.name, '.pdf', destFolder);

  // Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  //alert( 'Documents saved as PDF' );

  }

  }

  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();

    options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  return options;

}

function getTargetFile(docName, ext, destFolder) {

  var newName = "";

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName += docName.substring(0, dot);

  newName += ext;

  }

  var myFile = new File( destFolder + '/' + newName );

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

//Close the open Document Command

app.documents[0].close(SaveOptions.DONOTSAVECHANGES)

//This line is set to clear the file out of the HotFolder when complete... Works great

var myFolder = Folder( '~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/IN' );

  var myFiles = myFolder.getFiles();

  for(var i=myFiles.length - 1; i > -1;  i--){

    myFiles.remove();

  };

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 16, 2016 Dec 16, 2016

I think that your base script should like this (without comments):

//@target illustrator

main();

function main() {

  var aitFile = File('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/ZTemplate/Zund Setup.ait');

  app.open(aitFile);

  var foldPath = '~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/IN'

  var fold     = Folder(foldPath);

  var files    = fold.getFiles();

  var file, newImg, doc, artboards, img;

  for (var j = 0; j < files.length; j++) {

    file            = files;

    newImg          = activeDocument.placedItems.add();

    newImg.file     = file;

    newImg.position = [200, -300];

  }

  doc                       = app.activeDocument;

  artboards                 = doc.artboards;

  img                       = doc.placedItems[0];

  img.left                  = 0;

  img.top                   = 0;

  artboards[0].artboardRect = [0, 0, img.width, -(img.height)];

  app.executeMenuCommand('fitall');

  addThroughCut();

  wrapper('BRINGTOFRONT');

  prnt();

  saveAsPdf('Proof' + app.activeDocument.placedItems[0].file.name);

  wrapper('SENDTOBACK');

  saveAsPdf(app.activeDocument.placedItems[0].file.name);

  app.documents[0].close(SaveOptions.DONOTSAVECHANGES);

  files = myFolder.getFiles();

  for (var i = files.length - 1; i > -1; i--) {

    files.remove();

  }

  /**

   * LIBRARY

   * */

  function addThroughCut() {

    var doc                   = app.activeDocument,

        layers                = doc.layers,

        swatches              = doc.swatches,

        artboards             = doc.artboards,

        bleed                 = 18,

        img                   = doc.placedItems[0],

        docSize               = [img.width, img.height],

        artLay,

        cutLay;

    img.left                  = 0;

    img.top                   = 0;

    artboards[0].artboardRect = [0, 0, docSize[0], -(docSize[1])];

    _initLayers();

    _addThroughCut();

    layers["Layer 1"].remove();

    function _initLayers() {

      artLay      = layers.add();

      artLay.name = "Artwork";

      img.moveToBeginning(artLay);

      cutLay      = layers.add();

      cutLay.name = "Through Cut";

    }

    function _addThroughCut() {

      var cutLine         = cutLay.pathItems.rectangle(-(bleed), bleed, docSize[0] - (bleed * 2), docSize[1] - (bleed * 2));

      cutLine.filled      = false;

      cutLine.strokeColor = swatches["Through Cut"].color;

    }

  }

  function wrapper(zOrdMeth) {

    var doc          = app.activeDocument;

    var layers       = doc.layers;

    var artLayer     = layers["Artwork"];

    var thruCutLayer = layers["Through Cut"];

    thruCutLayer.zOrder(ZOrderMethod[zOrdMeth]);

  }

  function prnt() {

    var storeUserInteract = userInteractionLevel;

    var d                 = activeDocument;

    var jbOpts            = new PrintJobOptions();

    var opts              = new PrintOptions();

    opts.printPreset      = "JEFF_HP";

    opts.jobOptions       = jbOpts;

    userInteractionLevel  = UserInteractionLevel.DONTDISPLAYALERTS;

    d.print(opts);

    userInteractionLevel = storeUserInteract;

  }

  function saveAsPdf(targFileName) {

    var destFolder = null;

    try {

      if (app.documents.length > 0) {

        destFolder = Folder('~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/OUT');

        if (destFolder !== null) {

          var options, i, sourceDoc, targetFile;

          options           = _getOptions();

          options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

          for (i = 0; i < app.documents.length; i++) {

            sourceDoc  = app.documents;

            targetFile = _getTargetFile(targFileName, '.pdf', destFolder); /// This is the line I added "Proof+" to the name that's not working

            sourceDoc.saveAs(targetFile, options);

          }

        }

      }

      else {

        throw new Error('There are no document open!');

      }

    }

    catch (e) {

    }

    function _getOptions() {

      var options       = new PDFSaveOptions();

      options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

      return options;

    }

    function _getTargetFile(docName, ext, destFolder) {

      var newName = "";

      if (docName.indexOf('.') < 0) {

        newName = docName + ext;

      } else {

        var dot = docName.lastIndexOf('.');

        newName += docName.substring(0, dot);

        newName += ext;

      }

      var myFile = new File(destFolder + '/' + newName);

      if (myFile.open("w")) {

        myFile.close();

      }

      else {

        throw new Error('Access is denied');

      }

      return myFile;

    }

  }

}

You are running the scripts through ExtendScriptToolkit and see where errors occur?

ps. Can you format the code in the same way?

link_advancedEditor.png

sintax_javascript.png

Thank you!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2016 Dec 16, 2016

I figured it out... There was a loop or something going on in the Moving Layers Forward and Back... Since I had it listed before and after printing... it was undoing itself... I simplified the code for both... and Boom! it worked Perfect... I also was able to add an extra step of saving a proof .pdf with the cut lines in front... and a Hi-res final with the cut lines hidden behind the artwork...

I'm still not sure I understand what all's going on in the save to .pdf command... there seems to be a lot of checks and returns that could be simplified if I understood it better... I game if anybody wants to take time to break it down.... I'd love to learn more...

// Save as pdf

  sourceDoc.saveAs( targetFile, options );

  }

  //alert( 'Documents saved as PDF' );

  }

  }

  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();

    options.pDFPreset = "Dynagraphics PDF - Flat - Layers"

  return options;

}

function getTargetFile(docName, ext, destFolder) {

  var newName = "";

  if (docName.indexOf('.') < 0) {

  newName = docName + ext;

  } else {

  var dot = docName.lastIndexOf('.');

  newName += docName.substring(0, dot);

  newName += ext;

  }

  var myFile = new File( destFolder + '/' + newName );

  if (myFile.open("w")) {

  myFile.close();

  }

  else {

  throw new Error('Access is denied');

  }

  return myFile;

}

Thanks

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2016 Dec 16, 2016

williamadowling

Any chance you can help me understand better what's going on in the .pdf save portion of my script... I'm putting it in two places.. because I need it to save a file in two different states (before some actions are ran... and after)...

However... I can get my two versions to run ok separately but I'm thinking like my issue of moving layers... there's a loop or check function in there that's negating them from running together...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Dec 16, 2016 Dec 16, 2016

The function to save to pdf can be simplify to that (for better understanding, and do not need complicate if it will work):

saveAsPdf(

    '~/Desktop/Illustrator Hot Folder/Add Zund-Print-Save/OUT',

    'Proof' + activeDocument.placedItems[0].file.name,

    "Dynagraphics PDF - Flat - Layers"

);

/**

* sample save the activeDocument to the pdf file

*

* @param {String} targFoldPath - any destination folder path

* @param {String} targFileName - the activeDoocument.name or any another name

* @param {String} pdfPresName - the name of existing pdf preset

* */

function saveAsPdf(targFoldPath, targFileName, pdfPresName) {

  var destFolder    = new Folder(targFoldPath);

  var pdfOpts       = new PDFSaveOptions();

  pdfOpts.pDFPreset = pdfPresName;

  var targFile      = new File(destFolder + '/' + targFileName);

  activeDocument.saveAs(targFile, pdfOpts);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 11, 2017 Jan 11, 2017

Quick question.. I'm using your format for saving .pdf files... but I want to move the 'Proof" that's being added to the filename to the end of the name rather than the beginning... I tried simply moving it like so but it didn't work... can you please assist on how to make this happen... - Thanks

saveAsPdf( 

    '~/Desktop/Illustrator Hot Folder/Reveal Zund Marks/OUT', 

    activeDocument.placedItems[0].file.name+'- Proof', 

    "Dynagraphics PDF - Flat - Layers" 

); 

/**

* sample save the activeDocument to the pdf file

*

* @param {String} targFoldPath - any destination folder path

* @param {String} targFileName - the activeDoocument.name or any another name

* @param {String} pdfPresName - the name of existing pdf preset

* */ 

function saveAsPdf(targFoldPath, targFileName, pdfPresName) { 

  var destFolder    = new Folder(targFoldPath); 

  var pdfOpts       = new PDFSaveOptions(); 

  pdfOpts.pDFPreset = pdfPresName; 

  var targFile      = new File(destFolder + '/' + targFileName); 

  activeDocument.saveAs(targFile, pdfOpts); 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 11, 2017 Jan 11, 2017

" - Proof" should be at the end of your file name... What is the result you're currently getting?

You're saving the file as (name of placed item) + " - Proof". So assuming your placed image is called "my_placed_image", the snippet you posted above should result in a file called:

my_placed_image - Proof.pdf

Can you post some screenshots of your results? I can't see a problem.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Dec 16, 2016 Dec 16, 2016

Thank you... I was wondering how to post the code correctly...

Thanks for all your help... I have it working great now....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 11, 2017 Jan 11, 2017

Well... I agree that I should be getting a result of "Placed Filename - PROOF"...

but unfortunately it's not adding the " - Proof" after the filename... The original version had it at the beginning of the line and it worked great, but I needed to move it to the end and have not had any success....

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 11, 2017 Jan 11, 2017

Ok. I thought you meant that " - Proof" was somehow being added to the beginning of the string which just didn't make any sense.

So your resulting filename is "my_placed_image.pdf"?

try this:

 

saveAsPdf(

     '~/Desktop/Illustrator Hot Folder/Reveal Zund Marks/OUT',

     activeDocument.placedItems[0].file.name,

     'Dynagraphics PDF - Flat - Layers'

);

function saveAsPdf(targFoldPath, targFileName, pdfPresName)

{

     var destFolder = new Folder (targFoldPath);

     var pdfOpts = new PDFSaveOptions();

     pdfOpts.pDFPreset = pdfPresName;

     var targFile = new File(destFolder + "/" + targFileName + " - Proof");

     app.activeDocument.saveAs(targFile, pdfOpts);

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2017 Jan 12, 2017

Unfortunately... that's still not working... it's not adding anything after the placed image file name... I've tried several combinations trying to do it... but there's something I'm missing... Any additional help o-marat

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 12, 2017 Jan 12, 2017

What if you add an extension to the end?

var targFile = new File(destFolder + "/" + targFileName + " - Proof.pdf");

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jan 12, 2017 Jan 12, 2017

That worked... Not sure why... but it did... Thanks so much

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Mentor ,
Jan 12, 2017 Jan 12, 2017
LATEST

I didn't test any of it and I've never had that issue. But  my guess is that ESTK won't save a file without an extension, but it fails quietly... I'm sure Adobe would tell us that's a feature, but it's obviously a bug.

Glad you got it working. 😃

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines