PathPointInfo.ancor units problem

Discussion of actual or possible Photoshop Scripting Bugs, Anomalies and Documentation Errors

Moderators: xbytor, DavideBarranca, Paul MR


PathPointInfo.ancor units problem

Postby ravdouha » Thu Dec 10, 2009 9:10 am

It seems that PathPointInfo.ancor is NOT an array of UnitValue (in spite of "CS4 JavaScript Scripting Reference"), but it is an array of numbers (x, y coordinates) based ALWAYS on 72 dpi resolution.
Example: run "PathItem sample script" (p.138), then change the new document resolution from 72 to 1000:
Code: Select all
var docRef = app.documents.add(5000, 7000, 1000, "Simple Line")

Run rhe script again and look at the result... The new path object is more bigger!

The original "Paths.jsx" code from "JavaScript Scripting Reference" is below:
Code: Select all
// Save the current preferences
var startRulerUnits = app.preferences.rulerUnits
var startTypeUnits = app.preferences.typeUnits
var startDisplayDialogs = app.displayDialogs
// Set Adobe Photoshop CS4 to use pixels and display no dialogs
app.preferences.rulerUnits = Units.PIXELS
app.preferences.typeUnits = TypeUnits.PIXELS
app.displayDialogs = DialogModes.NO
// first close all the open documents
while (app.documents.length) {
// create a document to work with
var docRef = app.documents.add(5000, 7000, 72, "Simple Line")
//line 1--it’s a straight line so the coordinates for anchor, left, and right
//for each point have the same coordinates
var lineArray = new Array()
lineArray[0] = new PathPointInfo
lineArray[0].kind = PointKind.CORNERPOINT
lineArray[0].anchor = Array(100, 100)

lineArray[0].leftDirection = lineArray[0].anchor
lineArray[0].rightDirection = lineArray[0].anchor
lineArray[1] = new PathPointInfo
lineArray[1].kind = PointKind.CORNERPOINT
lineArray[1].anchor = Array(150, 200)
lineArray[1].leftDirection = lineArray[1].anchor
lineArray[1].rightDirection = lineArray[1].anchor
var lineSubPathArray = new Array()
lineSubPathArray[0] = new SubPathInfo()
lineSubPathArray[0].operation = ShapeOperation.SHAPEXOR
lineSubPathArray[0].closed = false
lineSubPathArray[0].entireSubPath = lineArray
// line 2
var lineArray2 = new Array()
lineArray2[0] = new PathPointInfo
lineArray2[0].kind = PointKind.CORNERPOINT
lineArray2[0].anchor = Array(150, 200)
lineArray2[0].leftDirection = lineArray2[0].anchor
lineArray2[0].rightDirection = lineArray2[0].anchor
lineArray2[1] = new PathPointInfo
lineArray2[1].kind = PointKind.CORNERPOINT
lineArray2[1].anchor = Array(200, 100)
lineArray2[1].leftDirection = lineArray2[1].anchor
lineArray2[1].rightDirection = lineArray2[1].anchor
lineSubPathArray[1] = new SubPathInfo()
lineSubPathArray[1].operation = ShapeOperation.SHAPEXOR
lineSubPathArray[1].closed = false
lineSubPathArray[1].entireSubPath = lineArray2
//ice cream curve
//it’s a curved line, so there are 3 points, not 2
//coordinates for the middle point (lineArray3[1]) are different.
//The left direction is positioned "above" the anchor on the screen.
//The right direction is positioned "below" the anchor
//You can change the coordinates for these points to see
//how the curve works...
var lineArray3 = new Array()
lineArray3[0] = new PathPointInfo
lineArray3[0].kind = PointKind.CORNERPOINT
lineArray3[0].anchor = Array(200, 100)
lineArray3[0].leftDirection = lineArray3[0].anchor
lineArray3[0].rightDirection = lineArray3[0].anchor
lineArray3[1] = new PathPointInfo
lineArray3[1].kind = PointKind.CORNERPOINT
lineArray3[1].anchor = Array(150, 50)
lineArray3[1].leftDirection = Array(100, 50)
lineArray3[1].rightDirection = Array(200, 50)
lineArray3[2] = new PathPointInfo
lineArray3[2].kind = PointKind.CORNERPOINT
lineArray3[2].anchor = Array(100, 100)
lineArray3[2].leftDirection = lineArray3[2].anchor
lineArray3[2].rightDirection = lineArray3[2].anchor

lineSubPathArray[2] = new SubPathInfo()
lineSubPathArray[2].operation = ShapeOperation.SHAPEXOR
lineSubPathArray[2].closed = false
lineSubPathArray[2].entireSubPath = lineArray3
//create the path item
var myPathItem = docRef.pathItems.add("A Line", lineSubPathArray)
// stroke it so we can see something
// Reset the application preferences
preferences.rulerUnits = startRulerUnits
preferences.typeUnits = startTypeUnits
displayDialogs = startDisplayDialogs

Mike Hale

PathPointInfo.ancor units problem

Postby Mike Hale » Thu Dec 10, 2009 3:10 pm

Yes that is one of the many places where the guide is wrong. All units in both pathPointInfo and pathPoint are numbers not unitValues.

Code: Select all
// run with at least one path in document
var obj = activeDocument.pathItems[0].subPathItems[0].pathPoints[0].anchor[0].constructor;
alert('Anchor is an UnitValue: '+(obj == UnitValue));
alert('Anchor is a Number: '+(obj == Number));


PathPointInfo.ancor units problem

Postby seanruiz » Sun Feb 07, 2010 9:22 pm

<du-> so ...
<du-> re: UnitValue anchors
<du-> apparently the javascript guide is wrong:
<du-> PathPointInfo anchors are always arrays based on 72 dpi
<du-> :(
<du-> weeeeiiiirddd...
<du-> a path with two coordinates 0,0 and 100,100 is 416px wide at 300dpi
<du-> and 72 goes into 300 4.16 times
<du-> what now?
<du-> i can make this work by _______
<du-> divide by 4.16
<du-> awesome.
<du-> so that only took my 4 or 5 days to figure out

Return to “Photoshop Scripting Bugs and Anomalies”

Who is online

Users browsing this forum: No registered users and 1 guest