This commit is contained in:
Unknown
2018-03-18 20:50:58 -04:00
parent 17a7f8ccd1
commit 7725110e35
13 changed files with 411 additions and 112 deletions

View File

@@ -8,27 +8,27 @@ function newFile(path) {
return f
}
// Returns an array of ArtLayers from a layerSet or an ArtLayer.
function getLayers(path) {
try {
var doc = app.activeDocument
var path = path.split('/')
var lyrs = doc.layerSets.getByName(path[0])
for (var i = 1; i < path.length; i++) {
try {
lyrs = lyrs.layerSets.getByName(path[i])
} catch (e) {
lyrs = { layers: [lyrs.layers.getByName(path[i])] } }
}
return lyrs
} catch (e) {
if (e.message.indexOf('User') == -1)
alert(err(e));
else
throw new Exception('User cancelled the operation');
}
}
// Moves a layer
function positionLayer(lyr, x, y, alignment){
if(lyr.iisBackgroundLayer||lyr.positionLocked) return
var layerBounds = lyr.bounds;
var layerX = layerBounds[0].value;
if (alignment == 'top' || alignment == null)
var layerY = layerBounds[1].value;
else if (alignment == 'bottom')
var layerY = layerBounds[3].value;
var deltaX = x-layerX;
var deltaY = y-layerY;
lyr.translate(deltaX, deltaY);
}
// Prints an error message.
function err(e) {
return 'ERROR: ' + e.message + ' at ' + e.fileName + ':' + e.line;
}
function bounds(lyr) {
return ('"Bounds": [[' + lyr.bounds[0] + ',' +
lyr.bounds[1] + '],[' + lyr.bounds[2] + ',' +
lyr.bounds[3] + ']]').replace(/ px/g, "");
}