title: How to create a path that matches page bounds with Photoshop javascript?
body: <p>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. </p>
  
  <p>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.  (I've tried the trick where you resize the page to have a resolution of 72 DPI first, and while that does center my paths on the page they are much smaller than they should be.  I'm also worried that resizing may damage data in the other layers.)</p>
  
  <p>What am I doing wrong?</p>
  
  <pre><code>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);
  </code></pre>