6 Replies Latest reply on Jan 20, 2016 3:57 PM by schroef

    [SCRIPTING] Set selection keeps pixels units while mm is set

    schroef Level 1

      Hi all,

       

      ive made this script quite a while back which helps me add guides and a layer called bleed. I use this quite often for my graphic design jobs, helps me a lot without loosing time on this repeating issue.

      Today i started to upgrade the script by so i can add the margin and the safety zone by input. Prior to this i always need to make the document with bleed, set rulers to pixels and than run the script. It always worked just fine, though it always used 3mm bleed and 3mm safety margin.

       

      I was looking at a script to catch input numers by using a var. that all is quite easy, ive got some background in as2 scripting for flash. What i dont understand is that in the beginning of the script i set the document units to MM. But as the script runs it somehow keeps taking the numbers as pixels. Ive made a dirty workaround by multiplying 11.338583 (pixelratio/dpi). But something isnt going right.

       

      My documents are set to 300dpi (print ready), how can i use this while keeping mm input?

       

      A other thing which bother me is that input give to shapes isnt correct. If i make a 3x3mm square and transform it later. In the dimension it says 2.96mm and not 3mm which i set in the input. Does this have to do with points/pica settings, i believe this is font type points and not for pixels

       

       

      // YOU NEED TO PUT THE DOCUMENT INCREMENDENTS TO PIXEL FOR THIS TO WORK

      //var strtRulerUnits = app.preferences.rulerUnits;

      //var docUnits = prompt ("Which Units do you use? (CAPATILISED)", "Set unit");

      //app.preferences.rulerUnits = Units[docUnits];

      var doc = app.activeDocument;

      var originalUnit = app.preferences.rulerUnits;

      app.preferences.rulerUnits = Units.PIXELS;

       

       

      var width = doc.width.value; 

      var height = doc.height.value; 

      var bleedAmount = prompt ("How much bleed do you want? (Millimeter)", 3);

      var safetyAmount = prompt ("What Safety marge do you want? (Millimeter)", 3);

      var bleedAmount = bleedAmount*11.338582677;//11.3385827;

      var safetyAmount = safetyAmount*11.338582677;//11.3385827; 11.338582677

       

       

      /// THIS ADDS GUIDES 3mm FROM EVERY EDGE + 3GUIDES inside

       

       

      activeDocument.guides.add (Direction.VERTICAL, width/2);

      activeDocument.guides.add (Direction.VERTICAL, 0);

      activeDocument.guides.add (Direction.VERTICAL, bleedAmount);

      activeDocument.guides.add (Direction.VERTICAL, (bleedAmount+safetyAmount));

      activeDocument.guides.add (Direction.HORIZONTAL, 0);

      activeDocument.guides.add (Direction.HORIZONTAL, height/2);

      activeDocument.guides.add (Direction.HORIZONTAL, +bleedAmount);

      activeDocument.guides.add (Direction.HORIZONTAL, (bleedAmount+safetyAmount));

      activeDocument.guides.add (Direction.VERTICAL, width);

      activeDocument.guides.add (Direction.VERTICAL, width-bleedAmount);

      activeDocument.guides.add (Direction.VERTICAL, width-(bleedAmount+safetyAmount));

      activeDocument.guides.add (Direction.HORIZONTAL, height);

      activeDocument.guides.add (Direction.HORIZONTAL, height-bleedAmount);

      activeDocument.guides.add (Direction.HORIZONTAL, height-(bleedAmount+safetyAmount));

       

       

      /// THIS ADDS A LAYER CALLED BLEED

      var NEW_LAYER_NAME = "• BLEED";

       

       

      var createNewLayer = function() {

          try {

              if (app.documents.length) {

                  var doc = activeDocument;

                  var layers = doc.artLayers;

                  var newLayer = layers.add();

                  if(NEW_LAYER_NAME) {

                      newLayer.name = NEW_LAYER_NAME;

                  }

                  doc.activeLayer = newLayer;

              }

          } catch (e) {

          }

      }

       

       

      createNewLayer();

       

       

      var grey = new SolidColor();

      grey.rgb["hexValue"] = "272727";

       

       

       

       

      activeDocument.selection.select.all;

      //app.activeDocument.selection.inverse;

      activeDocument.selection.fill(grey);

       

       

      // Make the bleed mask

      //activeDocument.selection.select.all;

      //activeDocument.selection.select(new Array (new Array(+bleedAmount,+bleedAmount),new Array(width-(+bleedAmount),+bleedAmount), new Array(width-(+bleedAmount), height-(+bleedAmount)),new Array((+bleedAmount), height-(+bleedAmount))));

      //activeDocument.selection.clear();

      //activeDocument.selection.deselect();

      /*

      [0,0],

      [0,100],

      [100,100],

      [100,0]

      */

       

       

       

       

      var shapeRef = [

      [bleedAmount,bleedAmount],

      [width-bleedAmount,bleedAmount],

      [width-bleedAmount,height-bleedAmount],

      [bleedAmount,height-bleedAmount]

      ]

      activeDocument.selection.select(shapeRef);

      activeDocument.selection.clear();

      activeDocument.selection.deselect();

       

       

      // MOVE LAYER TO TOP

      var layerRef = app.activeDocument.layers[0]

      activeDocument.activeLayer.move(layerRef, ElementPlacement.PLACEBEFORE);

      //activeDocument.activeLayer("Color Code").addProperty("Red");

       

       

      // RESTORE ORIGINAL DOCUMENT UNITS

      app.preferences.rulerUnits = originalUnit;