adobe-illustrator - adobe illustrator 脚本 - 矩形调整大小
问题描述
大家好!我试图创建一个脚本来创建一个给定大小的矩形,创建一个组和一个剪贴蒙版,然后将其调整为不同的 mm 大小。
例如,我有一个名为“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;}
}
解决方案
如果您的脚本适合您(但它对我不起作用)并且您想要的只是将图片的大小从 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);
推荐阅读
- git - 如何在不安装 Git 的情况下安装 Git 附带的 bash for windows?
- winapi - RegGetValue 一个使用 luajit ffi 的硬崩溃应用程序
- phpunit - Symfony 4 phpunit:KERNEL_CLASS env 变量错误
- ios - 如何在 SwiftUI 中使用 ForEach 中的 Section 项执行 onDelete
- azure-functions - Bot Framework Composer 自定义运行时启动命令
- matplotlib - plt.gcf() 中的语法错误。用于地理气候数据集
- html - 如何在 VScode 中直接在服务器上编辑代码
- hive - 使用 CTE 更新 hive 中表的列值
- r - 为什么 coord_sf() 会抛出 ERROR: st_normalize.sfc...domain must have a positive range?
- node.js - 将 Google API 凭据与应用一起分发是否安全?