Hi, I wanted to make a script that outputs the coordinates of a detailed shape in a file, can anybody fix/tell me what is wrong? Thanks.
Code: Select allvar doc = activeDocument;
var b = new File("C:\Users\<censored>\Pictures\Test\test.txt");
b.open('w');
if(hasSelection(doc)){
doc.selection.makeWorkPath(0.000000001);
var workPath = doc.pathItems.getByName("Work Path");
b.writeln(workPath.pathKind);
b.writeln("Number of Sub Paths = " +workPath.subPathItems.length);
for(var b =0;b<workPath.subPathItems.length;b++){
b.writeln("Sub Path "+b +" Closed = "+workPath.subPathItems.closed);
}
for(var b =0;b<workPath.subPathItems.length;b++){
b.writeln("\n\nSub Path "+b+" has " +workPath.subPathItems.pathPoints.length+ " Pathpoints");
b.writeln("Sub Path "+b+" Operation = " +workPath.subPathItems.operation);
for(var a =0;a<workPath.subPathItems.pathPoints.length;a++){
b.writeln("Kind - "+workPath.subPathItems.pathPoints[a].kind);
b.writeln("Anchor - "+workPath.subPathItems.pathPoints[a].anchor);
b.writeln("Left - "+workPath.subPathItems.pathPoints[a].leftDirection);
b.writeln("Right - "+workPath.subPathItems.pathPoints[a].rightDirection);
}
}
}
function hasSelection (doc) {
var res = false;
var as = doc.activeHistoryState;
doc.selection.deselect();
if (as != doc.activeHistoryState) {
res = true;
doc.activeHistoryState = as;
}
return res;
};
b.close();
Outputting polygon selection coordinates not working
-
Mike Hale
Outputting polygon selection coordinates not working
Tell you tell us about what is not working? Does it show any error messages? Not write the data to the file?
-
Rodonies
Outputting polygon selection coordinates not working
Says that b.writeln isn't a function.
(line 10)
(line 10)
-
Mike Hale
Outputting polygon selection coordinates not working
You have overwritten the file object in the variable b when you used later for a loop. I didn't test this but here is one way to avoid that error message.
Code: Select all var doc = activeDocument;
var datFile = new File("C:\Users\<censored>\Pictures\Test\test.txt");
datFile.open('w');
if(hasSelection(doc)){
doc.selection.makeWorkPath(0.000000001);
var workPath = doc.pathItems.getByName("Work Path");
datFile.writeln(workPath.pathKind);
datFile.writeln("Number of Sub Paths = " +workPath.subPathItems.length);
for(var b =0;b<workPath.subPathItems.length;b++){
datFile.writeln("Sub Path "+b +" Closed = "+workPath.subPathItems.closed);
}
for(var b =0;b<workPath.subPathItems.length;b++){
datFile.writeln("\n\nSub Path "+b+" has " +workPath.subPathItems.pathPoints.length+ " Pathpoints");
datFile.writeln("Sub Path "+b+" Operation = " +workPath.subPathItems.operation);
for(var a =0;a<workPath.subPathItems.pathPoints.length;a++){
datFile.writeln("Kind - "+workPath.subPathItems.pathPoints[a].kind);
datFile.writeln("Anchor - "+workPath.subPathItems.pathPoints[a].anchor);
datFile.writeln("Left - "+workPath.subPathItems.pathPoints[a].leftDirection);
datFile.writeln("Right - "+workPath.subPathItems.pathPoints[a].rightDirection);
}
}
}
function hasSelection (doc) {
var res = false;
var as = doc.activeHistoryState;
doc.selection.deselect();
if (as != doc.activeHistoryState) {
res = true;
doc.activeHistoryState = as;
}
return res;
};
datFile.close();
Code: Select all var doc = activeDocument;
var datFile = new File("C:\Users\<censored>\Pictures\Test\test.txt");
datFile.open('w');
if(hasSelection(doc)){
doc.selection.makeWorkPath(0.000000001);
var workPath = doc.pathItems.getByName("Work Path");
datFile.writeln(workPath.pathKind);
datFile.writeln("Number of Sub Paths = " +workPath.subPathItems.length);
for(var b =0;b<workPath.subPathItems.length;b++){
datFile.writeln("Sub Path "+b +" Closed = "+workPath.subPathItems.closed);
}
for(var b =0;b<workPath.subPathItems.length;b++){
datFile.writeln("\n\nSub Path "+b+" has " +workPath.subPathItems.pathPoints.length+ " Pathpoints");
datFile.writeln("Sub Path "+b+" Operation = " +workPath.subPathItems.operation);
for(var a =0;a<workPath.subPathItems.pathPoints.length;a++){
datFile.writeln("Kind - "+workPath.subPathItems.pathPoints[a].kind);
datFile.writeln("Anchor - "+workPath.subPathItems.pathPoints[a].anchor);
datFile.writeln("Left - "+workPath.subPathItems.pathPoints[a].leftDirection);
datFile.writeln("Right - "+workPath.subPathItems.pathPoints[a].rightDirection);
}
}
}
function hasSelection (doc) {
var res = false;
var as = doc.activeHistoryState;
doc.selection.deselect();
if (as != doc.activeHistoryState) {
res = true;
doc.activeHistoryState = as;
}
return res;
};
datFile.close();
-
Rodonies
Outputting polygon selection coordinates not working
Derp, I copied the script and adapted it but didn't notice it was used in a loop.
EDIT: It doesn't give an error but it doesn't give me a file.
EDIT: It doesn't give an error but it doesn't give me a file.
-
Mike Hale
Outputting polygon selection coordinates not working
Make sure that the path in line two is valid on your system. And make sure you have a document open with an active selection.
-
Rodonies
Outputting polygon selection coordinates not working
It is, I changed the path to C:\Test.txt and it still doesn't give me a file, can you try it with a random picture?
Edit: After I run the script the selection turns red, I think the only part that isn't working is creating a file.
P.S. I am running in administrator mode
I just tried creating the file test.txt in C:\ and changed "new File" to "File", but still doesn't give the coordinates.
Edit: After I run the script the selection turns red, I think the only part that isn't working is creating a file.
P.S. I am running in administrator mode
I just tried creating the file test.txt in C:\ and changed "new File" to "File", but still doesn't give the coordinates.
-
Mike Hale
Outputting polygon selection coordinates not working
The script is working for me writing the file to the desktop. Note that it takes a while to run and can create a large text file. Here is part of the text file
undefined
Number of Sub Paths = 1
Sub Path 0 Closed = true
Sub Path 0 has 1165 Pathpoints
Sub Path 0 Operation = ShapeOperation.SHAPEXOR
Kind - PointKind.SMOOTHPOINT
Anchor - 711,556
Left - 711.9999,555.6667
Right - 710.6667,556.9999
Kind - PointKind.SMOOTHPOINT
Anchor - 714,555
Left - 714,554.6667
Right - 713.0001,555.3333
Kind - PointKind.SMOOTHPOINT
Anchor - 714,554
Left - 717.9996,553.3334
Right - 714,554.3333
Kind - PointKind.SMOOTHPOINT
Anchor - 726,552
Left - 726,551.6667
Right - 722.0004,552.6666
Kind - PointKind.SMOOTHPOINT
undefined
Number of Sub Paths = 1
Sub Path 0 Closed = true
Sub Path 0 has 1165 Pathpoints
Sub Path 0 Operation = ShapeOperation.SHAPEXOR
Kind - PointKind.SMOOTHPOINT
Anchor - 711,556
Left - 711.9999,555.6667
Right - 710.6667,556.9999
Kind - PointKind.SMOOTHPOINT
Anchor - 714,555
Left - 714,554.6667
Right - 713.0001,555.3333
Kind - PointKind.SMOOTHPOINT
Anchor - 714,554
Left - 717.9996,553.3334
Right - 714,554.3333
Kind - PointKind.SMOOTHPOINT
Anchor - 726,552
Left - 726,551.6667
Right - 722.0004,552.6666
Kind - PointKind.SMOOTHPOINT