这可能是一个非常基本的问题,但是我无法获得一个脚本来调整脚本中先前创建的文本图层的大小。我在脚本的开头创建了一个新的文本层,它应该根据文档的大小进行调整,但是脚本会尝试调整锁定的Background层的大小,从而导致错误,因为Transform命令不可用。当我使用单独的脚本创建文本图层时,我不会遇到此问题,就在同一脚本中创建新图层时。我真的只想在一个动作中运行一个脚本而不是两个。
这是脚本的相关部分(我已经注释了之前选择新文本图层的一些努力):
var doc = app.activeDocument;
var layer = doc.activeLayer;
var newTextLayer = doc.artLayers.add();
newTextLayer.kind = LayerKind.TEXT;
newTextLayer.name = "textLayer";
var text = newTextLayer.textItem;
text.contents = "TEST TEXT";
text.color = white;
app.preferences.rulerUnits = Units.PIXELS;
//create the color for the tab extension
var black = new SolidColor();
black.rgb.hexValue = "111111";
app.backgroundColor = black;
//******************FOR EXTENDING CANVAS AND POSITIONING/RESIZING THE TEXT LAYER**************************
var orgWidth = doc.width;
var orgHeight = doc.height;
//var topLayer = app.activeDocument.layers.index(0);
//var txtLayer = app.activeDocument.TextItem.getByName("textLayer");
if(orgWidth>orgHeight) //if document is landscape, resize text to fill a smaller portion of the tab
{
//doc.activeLayer = doc.layers["textLayer"];
//doc.layers.getByName("textLayer");
layer.resize(((orgWidth-orgWidth*.2)/(layer.bounds[2]- layer.bounds[0]))*100,(orgWidth*.03/(layer.bounds[3]- layer.bounds[1]))*100,AnchorPosition.TOPLEFT);
doc.resizeCanvas(doc.width, (orgHeight + orgWidth*.04), AnchorPosition.TOPCENTER);
layer.translate(undefined, new UnitValue(0-layer.bounds[1].as('px'),'px'));
layer.translate(undefined, orgHeight);
layer.translate(undefined, (orgWidth*.02-((layer.bounds[3]-layer.bounds[1])/2.3)));
}
else //otherwise, resize text to fill a larger portion of the tab
{
//doc.activeLayer = doc.layers["textLayer"];
//doc.layers.getByName("textLayer");
layer.resize(((orgWidth-orgWidth*.05)/(layer.bounds[2]- layer.bounds[0]))*100,(orgWidth*.03/(layer.bounds[3]- layer.bounds[1]))*100,AnchorPosition.TOPLEFT);
doc.resizeCanvas(doc.width, (orgHeight + orgWidth*.04), AnchorPosition.TOPCENTER);
layer.translate(undefined, new UnitValue(0-layer.bounds[1].as('px'),'px'));
layer.translate(undefined, orgHeight);
layer.translate(undefined, (orgWidth*.02-((layer.bounds[3]-layer.bounds[1])/2.3)));
}