如何使智能对象图层中心到画布?(How to align Smart Object layer ce

2019-10-18 20:29发布

我一直在使用Google整天找到一种方法来对准其转换为智能对象中心通过脚本进行画布层,但还没有找到一个解决方案为止。 我结束了下面的代码,但它不会做的工作。 任何人都可以帮助吗?

var baseFile = new File(openDialog()); //open base JPEG file
var workFile = new File(openDialog()); //open work JPEG file
var baseDoc = app.open(baseFile);
var workDoc = app.open(workFile);

createSO(workDoc.layers[0]);
workDoc.resizeImage(280,280);
workDoc.artLayers[0].duplicate(baseDoc, ElementPlacement.INSIDE);
app.activeDocument = baseDoc;

var Hoffset = (baseDoc.width - workDoc.width) / 2;
var Voffset = (baseDoc.height - workDoc.height) / 2;
baseDoc.layers[1].position = Array(Hoffset, Voffset);

function createSO(){
    var doc = app.activeDocument;
    var idnewPlacedLayer = stringIDToTypeID( "newPlacedLayer" );
    executeAction( idnewPlacedLayer, undefined, DialogModes.NO );
    return doc.activeLayer;
}

Answer 1:

我认为你可以简化这种方式有点:

var baseFile = new File(openDialog()); //open base JPEG file
var workFile = new File(openDialog()); //open work JPEG file
var baseDoc = app.open(baseFile);
var workDoc = app.open(workFile, undefined, true);

workDoc.resizeImage(280, 280);
var duplicated = workDoc.artLayers[0].duplicate(baseDoc, ElementPlacement.INSIDE);
var Hoffset = (baseDoc.width - workDoc.width) / 2;
var Voffset = (baseDoc.height - workDoc.height) / 2;

app.activeDocument = baseDoc;

duplicated.translate(Hoffset, Voffset);

这里的要点是用translate法; 但您也可避免创建createSO功能,采用的第三个参数app.open (即asSmartObject )。



文章来源: How to align Smart Object layer center to the canvas?