论坛帮助 |
社区圈子 |
日历事件 |
2022-08-26, 14:54 | #1 | ||
|
|||
java爱好者
等级: 六袋长老
|
代码:
var doc = app.activeDocument; var pt = 72 / 25.4; var ps = getPs(doc.selection); w = ps[6][0] - ps[5][0]>ps[5][0] - ps[4][0]?Math.round((ps[6][0] - ps[5][0]) / pt, 3):Math.round((ps[5][0] - ps[4][0]) / pt, 3); h = Math.round((ps[5][1] - ps[2][1]) / pt, 3); d = ps[6][0] - ps[5][0]<ps[5][0] - ps[4][0]?Math.round((ps[6][0] - ps[5][0]) / pt, 3):Math.round((ps[5][0] - ps[4][0]) / pt, 3); file_words_save_txt('C:\\1--1.txt', w + '-' + d + '-' + h) addText(ps[5], w + 'x' + d + 'x' + h); function file_words_save_txt(file_name, words) { /** * 文本存txt * 使用例子 * file_words_save_txt('','dj\r\nll简单\r\n123'); * file_words_save_txt('C:/Users/Administrator/Desktop/1.txt','dj\r\nll简单\r\n123') */ f = new File(file_name);//文件位置 f.open('w'); f.write(words); f.close(); } function addText(point, index) { var textRef = doc.textFrames.add(); textRef.contents = "【" + index + "】" + parseInt(point[0] + '') + "," + parseInt(point[1] + ''); textRef.left = point[0]; textRef.top = point[1]; } function getPs(sels) { var rect = new Rect(sels); var pointList = new Array(); //获取所有的点 for (var r = 0; r < sels.length; r++) { var shape = sels[r]; var ps = shape.pathPoints; for (var i = 0; i < ps.length; i++) { var direction = ps[i].rightDirection; pointList.push(direction); } } for (var i = 0; i < pointList.length - 1; i++) { for (var j = i + 1; j < pointList.length; j++) { { if (pointList[i][0] > pointList[j][0]) { max = pointList[j]; pointList[j] = pointList[i]; pointList[i] = max; } } } } var newPoints = new Array(); for (var i = 0; i < 10; i++) { newPoints.push(undefined); } /** * 7 8 9 * 4 5 6 * 1 2 3 */ var ml = rect.maxLeft; var mb = rect.minBottom; var mt = rect.maxTop; var mr = rect.maxRight; for (var i = 0; i < pointList.length; i++) { var point = pointList[i]; var x = point[0]; var y = point[1]; if (number1(x, ml) && number1(y, mb)) { newPoints[1] = point; } if (number1(x, ml) && number1(y, mt)) { newPoints[7] = point; } if (number1(x, mr) && number1(y, mt)) { newPoints[9] = point; } if (number1(x, mr) && number1(y, mb)) { newPoints[3] = point; } if (number7(x, ml) && number7(mr, x) && number1(y, mb)) { newPoints[2] = point; } if (number7(x, ml) && number7(mr, x) && number1(y, mt)) { newPoints[8] = point; } if (number7(x, ml) && number7(mr, x) && number7(y, mb) && number7(mt, y)) { newPoints[5] = point; } if (number7(y, mb) && number7(mt, y) && number1(x, ml)) { newPoints[4] = point; } if (number7(y, mb) && number7(mt, y) && number1(x, mr)) { newPoints[6] = point; } } for (var i = 0; i < newPoints.length; i++) { var point = newPoints[i]; if (undefined != point) { addText(point, (i)); } } function number7(a, b) { var rc = 7 * pt; return a > b && Math.abs(a - b) >= rc; } function number1(a, b) { var rc = 1 * pt; return Math.abs(a - b) <= rc; } /** 矩形类 */ function Rect(arr) { this.left = 0; this.right = 2; this.top = 1; this.bottom = 3; this.min = false; this.max = true; this.maxLeft = getMaxPosition(arr, this.left, this.min); this.maxRight = getMaxPosition(arr, this.right, this.max); this.maxTop = getMaxPosition(arr, this.top, this.max); this.minBottom = getMaxPosition(arr, this.bottom, this.min); this.width = this.maxRight - this.maxLeft; this.height = this.maxTop - this.minBottom; } /** * 获取极限坐标 蒙版对象会错 * [MENTION=343005]para[/MENTION]m {图形列表 可以是你选中的图形 doc.selection} shapeList * [MENTION=343005]para[/MENTION]m {bounds的下标} index * [MENTION=343005]para[/MENTION]m {取最大值还是最小值 true 表示最大值 false表示最小值} minOrMax * [MENTION=48433]return[/MENTION]s */ function getMaxPosition(shapeList, index, minOrMax) { var tempx = shapeList[0].geometricBounds[index];//第一个图形 的极限坐标 if (minOrMax) { for (i = 1; i < shapeList.length; i++) { if (tempx < shapeList[i].geometricBounds[index]) { tempx = shapeList[i].geometricBounds[index]; } } } else { for (i = 1; i < shapeList.length; i++) { if (tempx > shapeList[i].geometricBounds[index]) { tempx = shapeList[i].geometricBounds[index]; } } } return tempx; } return newPoints; } |
||
右列会员因为此帖价值甚高向 jialan75 表示感谢: |
火星来客 (2022-08-26)
|