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

Please help! Infuriating issue with printer presets and javascript

Explorer ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Hello world,

     I have an issue that is driving me insane. I am trying to make a script that will either install or modify/update a printer preset and this is my current code:

try { //Install
   var SNAPPI_C654_8point5x11 = app.printerPresets.add();
   with (SNAPPI_C654_8point5x11) {
   name =  "SNAPPI_C654_8.5x11";
   printer = "Bizhub C654e PS";
   pagePosition = PagePositions.centered;
   printBlankPages = true;
   cropMarks = false;
   pageRange =  PageRange.ALL_PAGES;
   pageWidth = "8.5in";
   pageHeight = "11in";
   paperSize = PaperSizes.CUSTOM;
   colorOutput = ColorOutputModes.COMPOSITE_CMYK;
   }

    }

    catch (err) { //Update

   with (app.printerPresets.itemByName("SNAPPI_C654_8.5x11")) {
   printer = "Bizhub C654e PS";
   pagePosition = PagePositions.centered;
   printBlankPages = true;
   cropMarks = false;
   pageRange =  PageRange.ALL_PAGES;
   pageWidth = "8.5in";
   pageHeight = "11in";
   paperSize = PaperSizes.CUSTOM;
   colorOutput = ColorOutputModes.COMPOSITE_CMYK;
   }

    }

I have also tried:

with (app.printerPresets.item("SNAPPI_C654_8.5x11")) {

as my catch.

The first time I run the script, everything works flawlessly. If I run it again with no catch, it crashes. If I run it again with a catch, it continues CREATING NEW PRESETS with default names (printer preset 1, 2, ....). Why does it keep creating NEW presets each time it is ran when I am EXPLICITLY referencing a preset that ALREADY EXISTS and do not have a command to .add?!?

This is essentially the installer script for a larger project I am working on and this one is driving me crazy. Any help is deeply appreciated!!!!!!

TOPICS
Scripting

Views

448

Translate

Translate

Report

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
Advisor ,
Mar 22, 2017 Mar 22, 2017

Copy link to clipboard

Copied

Just this time:

var SNAPPI_C654_8point5x11 = app.printerPresets.item('SNAPPI_C654_8.5x11');

if (!SNAPPI_C654_8point5x11.isValid) {

  SNAPPI_C654_8point5x11 = app.printerPresets.add({

    name: "SNAPPI_C654_8.5x11",

    printer: "Bizhub C654e PS",

    pagePosition: PagePositions.centered,

    printBlankPages: true,

    cropMarks: false,

    pageRange: PageRange.ALL_PAGES,

    pageWidth: "8.5in",

    pageHeight: "11in",

    paperSize: PaperSizes.CUSTOM,

    colorOutput: ColorOutputModes.COMPOSITE_CMYK

  });

}

Down the line, do yourself and those that might have to work after you with your code and read up a bit on JS conventions and style guides to see why you should not name your variables like "SNAPPI_C654_8point5x11" or use "with"

Votes

Translate

Translate

Report

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 ,
Mar 23, 2017 Mar 23, 2017

Copy link to clipboard

Copied

LATEST

Thanks! This is my first scripting project so I am still very new to all of this. Do you have any particular references or sites you would recommend? I only use with because I am not aware of another way to accomplish the same effect, how does isValid work, is it checking if the name is already a valid reference or if creating a new entry with that name is a valid action?

     Also, will this code also work to update the existing preset if ran more than once? The values may change in future versions and I want it to be able to update the presets to reflect possible changes. Thanks again for helping a newbie!

Votes

Translate

Translate

Report

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