Quantcast
Channel: Adobe Community : Popular Discussions - Photoshop Scripting
Viewing all articles
Browse latest Browse all 12244

How to set units when creating paths with a script?

$
0
0

I'm trying to update a script that used to work in Photoshop CS4 but which seems to completely ignore the units I'm using in Cloud.  The script below should create a path layer with two lines that form an X across the entire document. 

 

To test, I'm creating a new page that's 8.5 x 11 inches and 300 DPI.  I then run the script.  However, the the shape that is produced is huge and most of it is offscreen.  What am I doing wrong?

 

 

 

function Point(x, y)

{

          this.x = x;

          this.y = y;

}

 

 

function addVertexCorner(lineArray, x, y)

{

          var p0Info = new PathPointInfo();

          lineArray.push(p0Info);

          p0Info.kind = PointKind.CORNERPOINT;

          p0Info.anchor = new Array(x, y);

          p0Info.leftDirection = p0Info.anchor;

          p0Info.rightDirection = p0Info.anchor;

}

 

 

function appendLine(p0, p1, lineSubPathArray)

{

          var lineArray = new Array();

 

 

          addVertexCorner(lineArray, p0.x, p0.y);

          addVertexCorner(lineArray, p1.x, p1.y);

 

 

          var pathInfo = new SubPathInfo();

          lineSubPathArray.push(pathInfo);

          pathInfo.operation = ShapeOperation.SHAPEADD;

          pathInfo.closed = false;

          pathInfo.entireSubPath = lineArray;

}

 

 

function createPathLayer(title, subPathArray)

{

          var docRef = app.activeDocument;

 

 

          var originalUnit = app.preferences.rulerUnits;

 

 

          app.preferences.rulerUnits = Units.PIXELS;

 

 

          var myPathItem = docRef.pathItems.add(title, subPathArray);

 

 

          app.preferences.rulerUnits = originalUnit;

}

 

 

var docRef = app.activeDocument;

 

 

var imgWidth = docRef.width.as("px");

var imgHeight = docRef.height.as("px");

 

 

var p00 = new Point(0, 0);

var p10 = new Point(imgWidth, 0);

var p01 = new Point(0, imgHeight);

var p11 = new Point(imgWidth, imgHeight);

 

 

var lineSubPathArray = new Array();

 

 

appendLine(p00, p11, lineSubPathArray);

appendLine(p01, p10, lineSubPathArray);

 

 

createPathLayer("Big X", lineSubPathArray);


Viewing all articles
Browse latest Browse all 12244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>