大家好,י!我试着创建一个脚本,创建一个给定大小的矩形,创建一个组和一个剪切蒙版,然后将其调整为不同的大小( mm )。
例如,我有一个名称为"fish400“的图形,我用脚本创建了一个400X400的矩形,并将其裁剪成一个矩形。到目前一切尚好。我的问题是,我想调整剪辑的大小,将其所有内容调整为382。当我将高度设置为rec时。18号它的高度是385.1
我不是一个非常熟练的程序员,脚本可以写得更好,但我真的不明白我的错误。
下面是我的代码:
var doc = app.activeDocument;
var layers = doc.layers;
var myLayer = layers["Layer 1"]; //this defines the layer that you want to get the selection from
var vals = 0;
var tzim = 0;
var side = 0; //width || height
//mm convertor
function mm(n) {return n * 2.83464566929134;}
doc.selection = null; //ensure there is nothing in the document selected already. this way you only get the selection you want.
var found = false;
for(var a=0 ;a<doc.groupItems.length; a++)
{
if (doc.groupItems[a].name == "fish400") {vals = mm(400); tzim = mm(18); side = 1; found = true;}
}
if (found = true)
{
var rect = doc.pathItems.rectangle(0,0,vals,vals);
app.executeMenuCommand("selectall");
var groupItem = doc.groupItems.add();
var count = selection.length;
for(var i = 0; i < count; i++)
{
var item = selection[selection.length - 1];
item.moveToBeginning(groupItem);
}
groupItem.clipped = true;
item.top = center_point[0] + (item.height/2);
item.left = center_point[1] - (item.width/2);
if (side == 1) {groupItem.height -= tzim;} else if (side == 0) {groupItem.width -= tzim;}
}发布于 2021-08-23 10:53:52
如果你的脚本对你来说运行得很好(不过对我来说不行),你想要的就是为你的图片添加从400x400到382x382 mm的大小调整,你只需要在脚本的末尾添加以下几行:
var k = 382/400*100;
groupItem.resize(k,k);或者:
app.executeMenuCommand("selectall");
var sel = app.selection[0];
var k = 382/400*100;
sel.resize(k,k);https://stackoverflow.com/questions/68889864
复制相似问题