gpt4 book ai didi

javascript - 通过 javascript 在 Illustrator 中将图稿与画板对齐

转载 作者:行者123 更新时间:2023-11-30 17:44:01 24 4
gpt4 key购买 nike

我正在尝试通过 javascript 将 illustrator 中的对象定位到艺术板左侧的底部。我可以使用 javascript 访问该对象并对其执行功能,如“旋转”

if ( app.documents.length > 0) {
doc = app.activeDocument;
}


function traceImage(doc) {

doc.pageItems[0].rotate (30);


}

traceImage(doc);

但我无法找到一种简单的方法来定位/对齐画板底部/左侧的“pageItems[0]”。除了计算它的当前距离然后移动它之外,还有更简单的方法吗?谢谢。

最佳答案

同样,如果您希望将项目居中放置在画板上,您需要以不同方式处理高度和宽度。

if ( app.documents.length > 0) {
doc = app.activeDocument;

// Get the active Artboard index
var activeAB = doc.artboards[doc.artboards.getActiveArtboardIndex()];

// Get the right most X point of the Artboard
// artboardX + artboardWidth
var artboardRight = activeAB.artboardRect[0] + activeAB.artboardRect[2];
// Get the bottom most Y point of the Artboard
// artboardY + artboardHeight
var artboardBottom = activeAB.artboardRect[1] + activeAB.artboardRect[3];

// The page item you want to move. Reference it how you will. This just
// obviously grabs the first pageItem in the document.
var myPageItem = doc.pageItems[0];

// Here is where the magic happens. Set the position of the item.
// [0,0] would be at the top left, so we have to compensate for the artboard
// height and width. We add item's height then split it for the vertical
// offset, or we'd end up BELOW the artboard.
// Then we subtract the item's width and split the difference to center the
// item horizontally.
var horziontalCenterPosition = (artboardRight - myPageItem.width)/2;
var verticalCenterPosition = (artboardBottom + myPageItem.height)/2;

myPageItem.position = [horziontalCenterPosition, verticalCenterPosition];
}

关于javascript - 通过 javascript 在 Illustrator 中将图稿与画板对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20478970/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com