论坛帮助 |
社区圈子 |
日历事件 |
2023-03-23, 09:48 | #1 | ||
|
|||
java爱好者
等级: 六袋长老
|
//容差 假如对象靠近 画板边缘,但是又没有碰到的情况下,0.8毫米以内的形状也认为是需要拉伸的对象 var rc = 0.8 * pt; //拉伸到画板外3mm为止 var ls = 3 * pt; expand(); function expand() { var doc = app.activeDocument; for (var n = 0; n < doc.artboards.length; n++) { var art = new Artboard(n); for (var i = 0; i < doc.selection.length; i++) { var shape = doc.selection[i]; if(art.left> shape.left+shape.width||art.top<shape.top-shape.height||art.right<shape.left||art.bottom>shape.top){ //如果在画板外就跳过 continue; } var left = isRC(art.left, shape.left, rc, 'left'); var bottom = isRC(art.bottom, shape.top - shape.height, rc, 'bottom'); var right = isRC(art.right, shape.left + shape.width, rc, 'right'); var top = isRC(art.top, shape.top, rc, 'top'); if (left) { shape.width = shape.width + ls - (art.left - shape.left); shape.left = shape.left - ls + (art.left - shape.left); } if (right) { shape.width = shape.width + ls - (shape.left + shape.width - art.right); } if (bottom) { shape.height = shape.height + ls - (art.bottom - (shape.top - shape.height)); } if (top) { shape.height = shape.height + ls - (shape.top - art.top); shape.top = shape.top + ls - (shape.top - art.top); } } } } function isRC(a, b, rc, index) { if (index == 'left') return (a > b && a - b < ls) || Math.abs(a - b) <= rc; if (index == 'top') return (a < b && b - a < ls) || Math.abs(a - b) <= rc; if (index == 'right') return (a < b && b - a < ls) || Math.abs(a - b) <= rc; if (index == 'bottom') return (a > b && a - b < ls) || Math.abs(a - b) <= rc; return Math.abs(a - b) <= rc; } function Artboard(index) { var doc = app.activeDocument; /** * index 下标 (非必填 默认当前画板) * 画板类用于获取画板的属性 * 宽度,高度,坐标(上下左右垂直中,水平中),简单的信息 * * 例子 * artboard = Artboard() * artboard = Artboard(0) * 打印信息 * alert(artboard.info) */ index = index == undefined ? doc.artboards.getActiveArtboardIndex() : index var abBounds = doc.artboards[index].artboardRect; this.width = abBounds[2] - abBounds[0]; this.height = abBounds[1] - abBounds[3]; this.left = abBounds[0]; this.top = abBounds[1]; this.bottom = abBounds[3]; this.right = abBounds[2]; this.index = index; this.toString = function () { return '当前是第' + index + '个页面\n页面尺寸为' + this.width / pt + 'x' + this.height / pt + ' mm'; } } 使用教程如下 1.jpg 2.jpg 3.jpg |
||
2023-03-23, 09:59 | 只看该作者 #2 | |||
|
||||
学到的要教人,得到的要给人!
等级: 七袋长老
|
引用:
这个代码写的很优美啊,不愧是高手
__________________
学到的要教人,得到的要给人! 遥遥领先Pitstop、Qi动作指导教学 解决日常难题,提升数倍工作效率! |
|||