Copy link to clipboard
Copied
Hi Guys,
How to export image vertices data (each x=?, y=?)? Here I attached the image this explain exactly what i want.
Thanks,
Vasanth
// 2016, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.pathItems.length > 0) {
var theArray = collectPathPointsInfoFromDesc (myDocument, myDocument.pathItems[myDocument.pathItems.length - 1]);
for (var m = 0; m < theArray.length; m++) {
alert (("subpathitem "+m+" has the following pathpoints\n"+theArray
}
}
};
////// collect path points coordinates //////
function collectPathPointsInfoFromDesc (myDocument, thePath
...Copy link to clipboard
Copied
| Hit Cmd + T to get the transform controls. The control bar up at the top will have the x and y values. |
Copy link to clipboard
Copied
You may have to explain what you really mean.
Do you rotate/otherwise transform Layers/Smart Objects/Shapes/… and in which form do you need the coordinates afterwards?
By default Photoshop files’ zero-point is the upper left corner by the way.
Copy link to clipboard
Copied
Hi pfaffenbichler,
Thanks.
I want to know about the exact x, y positions of every break points. These values should be given to the scripting side. When i export the trimmed image (png image) its appear square or rectangle shape, because i can't export exact shape of that specified object. So i need to tell every vetice points x,y positions. Here i attached the sample image.
Copy link to clipboard
Copied
So you are talking about Paths with corner points without Bezier handles?
Are there multiple Paths or inly ever one per image?
Getting PathPoint information can be done with a Script as well as creating a txt- or some other file, you may want to ask for help over at
Copy link to clipboard
Copied
Thanks for your reply.
Exactly! I want photoshop scripting for generate values of path position.
Thanks
Vasanth
Copy link to clipboard
Copied
// 2016, use it at your own risk;
#target photoshop
if (app.documents.length > 0) {
var myDocument = app.activeDocument;
if (myDocument.pathItems.length > 0) {
var theArray = collectPathPointsInfoFromDesc (myDocument, myDocument.pathItems[myDocument.pathItems.length - 1]);
for (var m = 0; m < theArray.length; m++) {
alert (("subpathitem "+m+" has the following pathpoints\n"+theArray
}
}
};
////// collect path points coordinates //////
function collectPathPointsInfoFromDesc (myDocument, thePath) {
var originalRulerUnits = app.preferences.rulerUnits;
app.preferences.rulerUnits = Units.POINTS;
// based of functions from xbytor’s stdlib;
var ref = new ActionReference();
for (var l = 0; l < myDocument.pathItems.length; l++) {
var thisPath = myDocument.pathItems
if (thisPath == thePath && thisPath.kind == PathKind.WORKPATH) {
ref.putProperty(cTID("Path"), cTID("WrPt"));
};
if (thisPath == thePath && thisPath.kind != PathKind.WORKPATH && thisPath.kind != PathKind.VECTORMASK) {
ref.putIndex(cTID("Path"), l + 1);
};
if (thisPath == thePath && thisPath.kind == PathKind.VECTORMASK) {
var idPath = charIDToTypeID( "Path" );
var idPath = charIDToTypeID( "Path" );
var idvectorMask = stringIDToTypeID( "vectorMask" );
ref.putEnumerated( idPath, idPath, idvectorMask );
};
};
var desc = app.executeActionGet(ref);
var pname = desc.getString(cTID('PthN'));
// create new array;
var theArray = new Array;
var pathComponents = desc.getObjectValue(cTID("PthC")).getList(sTID('pathComponents'));
// for subpathitems;
for (var m = 0; m < pathComponents.count; m++) {
var listKey = pathComponents.getObjectValue(m).getList(sTID("subpathListKey"));
// for subpathitem’s count;
for (var n = 0; n < listKey.count; n++) {
theArray.push(new Array);
var points = listKey.getObjectValue(n).getList(sTID('points'));
// for subpathitem’s segment’s number of points;
for (var o = 0; o < points.count; o++) {
var anchorObj = points.getObjectValue(o).getObjectValue(sTID("anchor"));
var anchor = [anchorObj.getUnitDoubleValue(sTID('horizontal')), anchorObj.getUnitDoubleValue(sTID('vertical'))];
var thisPoint = [anchor];
theArray[theArray.length - 1].push(anchor);
};
};
};
// by xbytor, thanks to him;
function cTID (s) { return cTID || cTID = app.charIDToTypeID(s); };
function sTID (s) { return sTID || sTID = app.stringIDToTypeID(s); };
// reset;
app.preferences.rulerUnits = originalRulerUnits;
return theArray;
};
Copy link to clipboard
Copied
Great Thanks!
Copy link to clipboard
Copied
By the way: That Script only processes the last Path in the Paths Panel (because if a Shape Layer is selected its Vector Mask appears at the end of the list), if
• there are more than one Path or
• you want the active Path or
• …
you may have to adapt the Script.