论坛帮助 |
社区圈子 |
日历事件 |
2024-11-16, 17:58 | #1 | ||
|
|||
中级会员
等级: 七袋长老
|
请用这个AI修改的代码测试看看: if (app.selection.length === 0) { alert("未选择对象!"); } else { app.executeMenuCommand("copy"); var newDoc = app.documents.add(); newDoc.activate(); app.executeMenuCommand("paste"); var artboard = newDoc.artboards[0]; artboard.artboardRect = newDoc.visibleBounds; } var SELECTION = activeDocument.selection; if (SELECTION.length > 0) { var VIEW = app.activeDocument.activeView; var zoom = VIEW.zoom; // 将 zoom 暂时重置为 1,以准确计算可见范围的尺寸 VIEW.zoom = 1; var bounds = VIEW.bounds; var ViewW = (bounds[2] - bounds[0]) * 0.3527777778; // 转换为毫米 var ViewH = (bounds[1] - bounds[3]) * 0.3527777778; // 转换为毫米 VIEW.zoom = zoom; // 初始化边界值 var LeftX, TopY, RightX, BottomY; for (var num = 0; num < SELECTION.length; num++) { var SELECTED = SELECTION[num].geometricBounds; LeftX = (LeftX == undefined) ? SELECTED[0] : Math.min(LeftX, SELECTED[0]); TopY = (TopY == undefined) ? SELECTED[1] : Math.max(TopY, SELECTED[1]); RightX = (RightX == undefined) ? SELECTED[2] : Math.max(RightX, SELECTED[2]); BottomY = (BottomY == undefined) ? SELECTED[3] : Math.min(BottomY, SELECTED[3]); } // 计算选区的尺寸和中心点(转换为毫米) var WidthX = (RightX - LeftX) * 0.3527777778; var HeightY = (TopY - BottomY) * 0.3527777778; var CenterX = ((RightX + LeftX) / 2) * 0.3527777778; var CenterY = ((TopY + BottomY) / 2) * 0.3527777778; // 根据视窗比例计算适当的缩放值 var Zoom = (ViewW / ViewH < WidthX / HeightY) ? ViewW / WidthX : ViewH / HeightY; VIEW.zoom = Zoom * 0.9; // 设置缩放比例,留一些边距 VIEW.centerPoint = [CenterX / 0.3527777778, CenterY / 0.3527777778]; // 将毫米单位转换回点单位 } 此帖于 2024-11-16 18:13 被 cpclgw 编辑. |
||
回复时引用此帖 |