2 Replies Latest reply on Mar 23, 2017 11:12 AM by arekh2792424

    Please help! Infuriating issue with printer presets and javascript

    arekh2792424 Level 1

      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!!!!!!

        • 1. Re: Please help! Infuriating issue with printer presets and javascript
          Vamitul Level 4

          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"

          1 person found this helpful
          • 2. Re: Please help! Infuriating issue with printer presets and javascript
            arekh2792424 Level 1

            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!