2 Replies Latest reply on Jan 22, 2014 6:41 AM by kricket_kg

    How to set stroke to overprint and apply swatch? (InDesign CC)

    kricket_kg Level 1

      I have very limited knowledge of scripting but am trying to create a basic script that will aid our workflow in a fast-paced production environment. What I need the overall script to do in InDesign is:

       

      1. Create a new layer at the top of the stack called "dieline"
      2. On this layer, put a rectangle the same size as the document page size and center
      3. Apply a spot colour swatch called "dieline" (C0 M100 Y0 K0) to the rectangle stroke and set stroke to overprint
      4. Set stroke to 1pt, apply fill to none, align stroke to center

      5. Apply this rectangle to all pages of the document

       

      By piecing together other scripts I have found online, I was able to successfully run the script below BUT encounter 2 issues:
      - If a document already has a swatch called "dieline" in the swatch palette, the script errors out. I just need the script to either apply the spot colour swatch "dieline" and if the document doesnt have one, then create it.
      - I cannot figure out how to set the stroke to overprint!

       

      I am hoping someone can help me out! Here is the code:

       

       

      var myDoc = app.activeDocument;

       

      // set page origin to 0,0

      myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

       

      // get page dimensions

      var myY2 = myDoc.documentPreferences.pageHeight;

      var myX2 = myDoc.documentPreferences.pageWidth;

       

      // define page count

      var myPagesTotal = myDoc.pages.length;

       

      // new layer to top of stack

      var myNewLayer = myDoc.layers.add();

      myNewLayer.move(LocationOptions.atBeginning, undefined);

      myNewLayer.name = "dieline";

       

      // add dieline swatch and set parameters

      var spotDie = new Array(0, 100, 0, 0);

      myDoc.colors.add({model:ColorModel.SPOT, space:ColorSpace.CMYK, colorValue:spotDie, name:"dieline"});

       

      var i=0;

       

      while ( i<myPagesTotal) { var mySpread = myDoc.pages.item(i);

      var myBorder = mySpread.rectangles.add();

      myBorder.geometricBounds = ["0p0", "0p0", myY2, myX2];

      myBorder.strokeColor = "dieline";

      myBorder.fillColor = "None";

      myBorder.strokeWeight = "1pt";

      myBorder.strokeAlignment = StrokeAlignment.centerAlignment;

       

      i++;

      }

       

       

       

      MANY MANY THANKS!

      (using Indesign CC)

        • 1. Re: How to set stroke to overprint and apply swatch? (InDesign CC)
          Mi_D Level 3

          Hi Kricket;

           

          try below code i check in cs6 version

           

          var myDoc = app.activeDocument;

          var myLayer = myDoc.layers;

          var mycolor = myDoc.swatches

          var myPage = myDoc.pages;

          var flag=false;

          var color=false;

           

          myDoc.viewPreferences.rulerOrigin = RulerOrigin.pageOrigin;

          var myY2 = myDoc.documentPreferences.pageHeight;

          var myX2 = myDoc.documentPreferences.pageWidth;

          var myPagesTotal = myDoc.pages.length;

           

          checkLayer();

          checkcolor();

          placeFrame();

          function checkLayer(){

          for (var l=0; myLayer.length>l; l++){

              if (myLayer[l].name =="dieline"){

                  flag=true;

                  }

          }

              if (flag==false){

              var myNewLayer = myDoc.layers.add();

           

          myNewLayer.move(LocationOptions.atBeginning, undefined);

           

          myNewLayer.name = "dieline";

           

              }

          }

           

          function checkcolor(){

          for(var c=0;c<mycolor.length;c++) {

                if(mycolor[c].name=="dieline"){

                    color=true;

               }

          }

          // add dieline swatch and set parameters

          if (color==false){

              var spotDie = new Array(0, 100, 0, 0)

              myDoc.colors.add({model:ColorModel.SPOT, space:ColorSpace.CMYK, colorValue:spotDie, name:"dieline"});

              }

          }

           

          function placeFrame(){

          for (var p=0; myPage.length>p; p++){

              var myBorder = myPage[p].rectangles.add();

             myBorder.move (myDoc.layers.item ("dieline"));

              myBorder.geometricBounds = ["0p0", "0p0", myY2, myX2];

              myBorder.strokeColor = "dieline";

              myBorder.overprintStroke=true;

              myBorder.fillColor = "None";

              myBorder.strokeWeight = "1pt";

              myBorder.strokeAlignment = StrokeAlignment.centerAlignment;

          }

          }

           

          Mi_D

          1 person found this helpful
          • 2. Re: How to set stroke to overprint and apply swatch? (InDesign CC)
            kricket_kg Level 1

            Thank you so much Mi_D, that works exactly as I need it to! Bless the Adobe Community!