Here's a new script with a better grid. If you try it, you'll see that the grid lines don't follow when the transformation is changed.
Code: Select all
function transformCurrentLayer() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc21 = new ActionDescriptor();
var ref13 = new ActionReference();
ref13.putEnumerated( cTID('Lyr '), cTID('Ordn'), cTID('Trgt') );
desc21.putReference( cTID('null'), ref13 );
desc21.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
executeAction( cTID('Trnf'), desc21, DialogModes.ALL);
};
var npoint = function(a, i, x, y) {
a = new PathPointInfo;
a.kind = PointKind.CORNERPOINT;
a.anchor = Array(x, y);
a.leftDirection = a.anchor;
a.rightDirection = a.anchor;
};
npath = function(a, i, la, closedp) {
a = new SubPathInfo();
a.operation = ShapeOperation.SHAPEXOR;
a.closed = closedp;
a[i].entireSubPath = la;
};
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
var startDisplayDialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
var docRef = app.activeDocument;
var ss = docRef.resolution/72.0;
var W = docRef.width.as("px"), H = docRef.height.as("px");
var LA1 = new Array(); npoint(LA1, 0, 0, 0); npoint(LA1, 1, 0, H/ss); npoint(LA1, 2, W/ss, H/ss); npoint(LA1, 3, W/ss, 0);
var LA2 = new Array(); npoint(LA2, 0, 0, H/2/ss); npoint(LA2, 1, W/ss, H/2/ss);
var LA3 = new Array(); npoint(LA3, 0, W/2/ss, 0); npoint(LA3, 1, W/2/ss, H/ss);
var lineSubPathArray = new Array();
npath(lineSubPathArray, 0, LA1, true);
npath(lineSubPathArray, 1, LA2, false);
npath(lineSubPathArray, 2, LA3, false);
var myPathItem = docRef.pathItems.add("Grid-01", lineSubPathArray);
myPathItem.makeSelection();
preferences.rulerUnits = startRulerUnits;
preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
transformCurrentLayer();
The second script, to complete the crop would simply be
Code: Select allvar docRef = app.activeDocument;
var myPathItem = app.activeDocument.pathItems.getByName("Grid-01");
myPathItem.makeSelection();
docRef.crop(docRef.selection.bounds);
Path bug in CS5 (not in CS6, apparently)
-
kpt
Path bug in CS5 (not in CS6, apparently)
The code I needed to transform the current path turned out to be
Code: Select allfunction transformCurrentPath() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc21 = new ActionDescriptor();
var ref13 = new ActionReference();
ref13.putEnumerated( cTID('Path'), cTID('Ordn'), cTID('Trgt') );
desc21.putReference( cTID('null'), ref13 );
desc21.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
executeAction( cTID('Trnf'), desc21, DialogModes.ALL);
};
Code: Select allfunction transformCurrentPath() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc21 = new ActionDescriptor();
var ref13 = new ActionReference();
ref13.putEnumerated( cTID('Path'), cTID('Ordn'), cTID('Trgt') );
desc21.putReference( cTID('null'), ref13 );
desc21.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
executeAction( cTID('Trnf'), desc21, DialogModes.ALL);
};
-
kpt
Path bug in CS5 (not in CS6, apparently)
And here's the complete script for my alternative crop tool (where the gridlines can be changed):
Code: Select allfunction transformCurrentPath() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc21 = new ActionDescriptor();
var ref13 = new ActionReference();
ref13.putEnumerated( cTID('Path'), cTID('Ordn'), cTID('Trgt') );
desc21.putReference( cTID('null'), ref13 );
desc21.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
executeAction( cTID('Trnf'), desc21, DialogModes.ALL);
};
var npoint = function(a, i, x, y) {
a = new PathPointInfo;
a.kind = PointKind.CORNERPOINT;
a.anchor = Array(x, y);
a.leftDirection = a.anchor;
a.rightDirection = a.anchor;
};
npath = function(a, i, la, closedp) {
a = new SubPathInfo();
a.operation = ShapeOperation.SHAPEXOR;
a.closed = closedp;
a[i].entireSubPath = la;
};
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
var startDisplayDialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
var docRef = app.activeDocument;
var ss = docRef.resolution/72.0;
var W = docRef.width.as("px"), H = docRef.height.as("px");
var LA0 = new Array(); npoint(LA0, 0, 0, 0); npoint(LA0, 1, 0, H/ss);
npoint(LA0, 2, W/ss, H/ss); npoint(LA0, 3, W/ss, 0);
var LA1 = new Array(); npoint(LA1, 0, 0, 0.333*H/ss); npoint(LA1, 1, W/ss, 0.333*H/ss);
var LA4 = new Array(); npoint(LA4, 0, 0, 0.667*H/ss); npoint(LA4, 1, W/ss, 0.667*H/ss);
var LA2 = new Array(); npoint(LA2, 0, 0.333*W/ss, 0); npoint(LA2, 1, 0.333*W/ss, H/ss);
var LA3 = new Array(); npoint(LA3, 0, 0.667*W/ss, 0); npoint(LA3, 1, 0.667*W/ss, H/ss);
var lineSubPathArray = new Array();
npath(lineSubPathArray, 0, LA0, true);
npath(lineSubPathArray, 1, LA1, false);
npath(lineSubPathArray, 2, LA2, false);
npath(lineSubPathArray, 3, LA3, false);
npath(lineSubPathArray, 4, LA4, false);
var myPathItem = docRef.pathItems.add("Grid-01", lineSubPathArray);
preferences.rulerUnits = startRulerUnits;
preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
transformCurrentPath();
myPathItem.makeSelection();
docRef.crop(docRef.selection.bounds);
myPathItem.remove();
Code: Select allfunction transformCurrentPath() {
function cTID(s) { return app.charIDToTypeID(s); };
function sTID(s) { return app.stringIDToTypeID(s); };
var desc21 = new ActionDescriptor();
var ref13 = new ActionReference();
ref13.putEnumerated( cTID('Path'), cTID('Ordn'), cTID('Trgt') );
desc21.putReference( cTID('null'), ref13 );
desc21.putEnumerated( cTID('FTcs'), cTID('QCSt'), cTID('Qcsa') );
executeAction( cTID('Trnf'), desc21, DialogModes.ALL);
};
var npoint = function(a, i, x, y) {
a = new PathPointInfo;
a.kind = PointKind.CORNERPOINT;
a.anchor = Array(x, y);
a.leftDirection = a.anchor;
a.rightDirection = a.anchor;
};
npath = function(a, i, la, closedp) {
a = new SubPathInfo();
a.operation = ShapeOperation.SHAPEXOR;
a.closed = closedp;
a[i].entireSubPath = la;
};
var startRulerUnits = app.preferences.rulerUnits;
var startTypeUnits = app.preferences.typeUnits;
var startDisplayDialogs = app.displayDialogs;
app.preferences.rulerUnits = Units.PIXELS;
app.preferences.typeUnits = TypeUnits.PIXELS;
app.displayDialogs = DialogModes.NO;
var docRef = app.activeDocument;
var ss = docRef.resolution/72.0;
var W = docRef.width.as("px"), H = docRef.height.as("px");
var LA0 = new Array(); npoint(LA0, 0, 0, 0); npoint(LA0, 1, 0, H/ss);
npoint(LA0, 2, W/ss, H/ss); npoint(LA0, 3, W/ss, 0);
var LA1 = new Array(); npoint(LA1, 0, 0, 0.333*H/ss); npoint(LA1, 1, W/ss, 0.333*H/ss);
var LA4 = new Array(); npoint(LA4, 0, 0, 0.667*H/ss); npoint(LA4, 1, W/ss, 0.667*H/ss);
var LA2 = new Array(); npoint(LA2, 0, 0.333*W/ss, 0); npoint(LA2, 1, 0.333*W/ss, H/ss);
var LA3 = new Array(); npoint(LA3, 0, 0.667*W/ss, 0); npoint(LA3, 1, 0.667*W/ss, H/ss);
var lineSubPathArray = new Array();
npath(lineSubPathArray, 0, LA0, true);
npath(lineSubPathArray, 1, LA1, false);
npath(lineSubPathArray, 2, LA2, false);
npath(lineSubPathArray, 3, LA3, false);
npath(lineSubPathArray, 4, LA4, false);
var myPathItem = docRef.pathItems.add("Grid-01", lineSubPathArray);
preferences.rulerUnits = startRulerUnits;
preferences.typeUnits = startTypeUnits;
app.displayDialogs = startDisplayDialogs;
transformCurrentPath();
myPathItem.makeSelection();
docRef.crop(docRef.selection.bounds);
myPathItem.remove();