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

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

Advocate ,
Dec 29, 2015 Dec 29, 2015

Copy link to clipboard

Copied

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;

TOPICS
Actions and scripting

Views

2.2K

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
Adobe
Advisor ,
Dec 29, 2015 Dec 29, 2015

Copy link to clipboard

Copied

Perhaps this line

    app.preferences.rulerUnits = Units.PIXELS;

should be this

    app.preferences.rulerUnits = Units.MM;

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
Advocate ,
Dec 29, 2015 Dec 29, 2015

Copy link to clipboard

Copied

Yes, i tried using MM but it somehow seems that measurements are still in pixels. Ive double checked it and measured the selection made, its really pixels than. Thats why i set it to pixels and at the end it set it back to MM

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
Advisor ,
Dec 29, 2015 Dec 29, 2015

Copy link to clipboard

Copied

You may have to change this

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

into this

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

And you may have to change these

   var width = doc.width.value; 

   var height = doc.height.value; 

to these

   var width = doc.width.as("mm"); 

   var height = doc.height.as("mm"); 

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
Advocate ,
Dec 30, 2015 Dec 30, 2015

Copy link to clipboard

Copied

Im going to try it. What i dont get is why we declare the unit in the beginning some values seem to be taking a different measuring. Is this correct? I thought declaring the unit sets it throughout the script as well

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
Advocate ,
Dec 30, 2015 Dec 30, 2015

Copy link to clipboard

Copied

Let me clear this when i use alert(width) and i have set the units to MM the alert gives me document width in exact mm width. But when photoshop executes it seems to take different measuring, that what baffles me.

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
Advocate ,
Jan 20, 2016 Jan 20, 2016

Copy link to clipboard

Copied

LATEST

Howcome we need to specify the mm again than? Thats what i dont get.

I havent tested your work around yet though, ive made mine now using PX first but its being a bit of cause pixels arent really good to convert to mm units    

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