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

rectangle function coordinates

Guest
Dec 12, 2009 Dec 12, 2009

Copy link to clipboard

Copied

Hello

     I am having trouble at something seemingly very simple.  I am trying to draw a rectangle using paths.  My issue is the coordiantes I use seem to be multiplied by 4.  I am trying to place the left top corner at 50,50 and I get it at 209,209 etc.  Hopefully someone can see the error in my ways as I have been looking at it way too long and thus cannot see the obvious.

<code>

function MyFuncAddRectangleShape(doc,x,y,width,height){
//define the path
$.writeln("x= ",x)
$.writeln("y= ",y)
$.writeln("width= ",width)
$.writeln("height= ",height)

var lineArray = new Array();
lineArray[0] = new PathPointInfo;
lineArray[0].kind = PointKind.CORNERPOINT;
lineArray[0].anchor = [x,y];//top left
lineArray[0].leftDirection = lineArray[0].anchor;
lineArray[0].rightDirection = lineArray[0].anchor;

lineArray[1] = new PathPointInfo;
lineArray[1].kind = PointKind.CORNERPOINT;
lineArray[1].anchor = [x+width, y];//top right
lineArray[1].leftDirection = lineArray[1].anchor;
lineArray[1].rightDirection = lineArray[1].anchor;

lineArray[2] = new PathPointInfo;
lineArray[2].kind = PointKind.CORNERPOINT;
lineArray[2].anchor = [x+width,y+height];//bottom right
lineArray[2].leftDirection = lineArray[2].anchor;
lineArray[2].rightDirection = lineArray[2].anchor;

lineArray[3] = new PathPointInfo;
lineArray[3].kind = PointKind.CORNERPOINT;
lineArray[3].anchor = [x,y+height];//bottom left
lineArray[3].leftDirection = lineArray[3].anchor;
lineArray[3].rightDirection = lineArray[3].anchor;

$.writeln(lineArray[0].anchor)
$.writeln(lineArray[1].anchor)
$.writeln(lineArray[2].anchor)
$.writeln(lineArray[3].anchor)

var lineSubPathArray = new Array();
lineSubPathArray[0] = new SubPathInfo();
lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR;
lineSubPathArray[0].closed = true;
lineSubPathArray[0].entireSubPath = lineArray;

// now make the path
var myPathItem = doc.pathItems.add("myPath", lineSubPathArray);

myPathItem.strokePath(ToolType.PENCIL);

}

// set operations
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.preferences.pointSize = PointType.POSTSCRIPT

// turn off dialog boxes
app.displayDialogs = DialogModes.NO;


// first close all the open documents
while (app.documents.length) {
app.activeDocument.close(SaveOptions.DONOTSAVECHANGES);
}


canvas = documents.add(5000,5000,300,"Canvas",NewDocumentMode.RGB,DocumentFill.WHITE,1,BitsPerChannelType.EIGHT);

MyFuncAddRectangleShape(canvas,
        50,
        50,
        50,
        50);

</code>

TOPICS
Actions and scripting

Views

859

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

correct answers 1 Correct answer

Guru , Dec 12, 2009 Dec 12, 2009

PathItem values are Numbers where n = pixels @ 72ppi. If your doc is not 72ppi you need to adjust the values used

MyFuncAddRectangleShape(canvas,
        50/(app.activeDocument.resolution/72),
        50/(app.activeDocument.resolution/72),
        50/(app.activeDocument.resolution/72),
        50/(app.activeDocument.resolution/72));

If you want the path to align with the pixels you will need to conver the values to integers.

Votes

Translate

Translate
Adobe
Guru ,
Dec 12, 2009 Dec 12, 2009

Copy link to clipboard

Copied

PathItem values are Numbers where n = pixels @ 72ppi. If your doc is not 72ppi you need to adjust the values used

MyFuncAddRectangleShape(canvas,
        50/(app.activeDocument.resolution/72),
        50/(app.activeDocument.resolution/72),
        50/(app.activeDocument.resolution/72),
        50/(app.activeDocument.resolution/72));

If you want the path to align with the pixels you will need to conver the values to integers.

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 12, 2009 Dec 12, 2009

Copy link to clipboard

Copied

An alternate approach is to set the dpi of your image to 72. Because of previous (and possibly existing) bugs in the PS API, working with the doc at 72dpi tends to avoid problems.

  var docRes = doc.resolution;
  doc.resizeImage( undefined, undefined, 72, ResampleMethod.NONE );

  try {

    // do stuff here....

  } finally {

     doc.resizeImage( undefined, undefined, docRes, ResampleMethod.NONE );

  }

-X

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
Guest
Dec 12, 2009 Dec 12, 2009

Copy link to clipboard

Copied

Thanks guys -- thought I was missing something simple

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
New Here ,
Oct 08, 2012 Oct 08, 2012

Copy link to clipboard

Copied

LATEST

Thank you post a nice post.

PATH TOO LONG solution provides a powerful and highly versatile solution to delete/unlock, copy/rename files and folders with long paths.

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