【问题标题】:adobe illustrator script- rectangle resizeadobe illustrator 脚本 - 矩形调整大小
【发布时间】:2021-10-23 15:25:14
【问题描述】:

大家好!我尝试创建一个脚本来创建一个给定大小的矩形,创建一个组和一个剪贴蒙版,然后将其调整为不同的毫米大小。

例如,我有一个名为“fish400”的图形,我将它剪辑到我用脚本创建的 400X400 的矩形中。到目前为止,一切都很好。我的问题是我想将剪辑的所有内容调整为 382。当我将高度设置为记录时。 size-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;}
}

【问题讨论】:

  • if (found = true) 总是true。您需要将= 替换为==。不过,在大多数情况下,它不会导致错误。
  • 并且变量(数组)center_point没有定义。它是什么?画板的中心?还是 groupItem 的中心?

标签: adobe-illustrator


【解决方案1】:

如果您的脚本适合您(但它不适用于我)并且您想要的只是将图片大小从 400x400 调整为 382x382 毫米,您可以在脚本末尾添加这些行:

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);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多