首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >adobe illustrator脚本-调整矩形大小

adobe illustrator脚本-调整矩形大小
EN

Stack Overflow用户
提问于 2021-08-23 08:58:28
回答 1查看 124关注 0票数 1

大家好,י!我试着创建一个脚本,创建一个给定大小的矩形,创建一个组和一个剪切蒙版,然后将其调整为不同的大小( mm )。

例如,我有一个名称为"fish400“的图形,我用脚本创建了一个400X400的矩形,并将其裁剪成一个矩形。到目前一切尚好。我的问题是,我想调整剪辑的大小,将其所有内容调整为382。当我将高度设置为rec时。18号它的高度是385.1

我不是一个非常熟练的程序员,脚本可以写得更好,但我真的不明白我的错误。

下面是我的代码:

代码语言:javascript
复制
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;}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-08-23 10:53:52

如果你的脚本对你来说运行得很好(不过对我来说不行),你想要的就是为你的图片添加从400x400到382x382 mm的大小调整,你只需要在脚本的末尾添加以下几行:

代码语言:javascript
复制
var k = 382/400*100;
groupItem.resize(k,k);

或者:

代码语言:javascript
复制
app.executeMenuCommand("selectall");
var sel = app.selection[0];
var k = 382/400*100;
sel.resize(k,k);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/68889864

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档