论坛帮助 |
社区圈子 |
日历事件 |
2024-11-16, 16:40 | #1 | ||
|
|||
正式会员
等级: 一袋长老
|
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 //var LeftX=TopY=RightX=BottomY=undefined; if(SELECTION.length>0){ var VIEW=app.activeDocument.activeView; var zoom=VIEW.zoom //centerPoint=app.activeDocument.activeView.centerPoint VIEW.zoom=1; var bounds=VIEW.bounds; var ViewW=bounds[2]-bounds[0]; var ViewH=bounds[1]-bounds[3]; VIEW.zoom=zoom; if(LeftX){LeftX=undefined;}; if(TopY){TopY=undefined;}; if(RightX){RightX=undefined;}; if(BottomY){BottomY=undefined;}; for(var num=0;num<SELECTION.length;num++){ var SELECTED=SELECTION[num].geometricBounds; var LeftX=(LeftX==undefined)?SELECTED[0]:((LeftX<SELECTED[0])?LeftX:SELECTED[0]); var TopY=(TopY==undefined)?SELECTED[1]:((TopY>SELECTED[1])?TopY:SELECTED[1]); var RightX=(RightX==undefined)?SELECTED[2]:((RightX>SELECTED[2])?RightX:SELECTED[2]); var BottomY=(BottomY==undefined)?SELECTED[3]:((BottomY<SELECTED[3])?BottomY:SELECTED[3]); }; var WidthX=RightX-LeftX; var HeightY=TopY-BottomY; var CenterX=(RightX+LeftX)/2; var CenterY=(TopY+BottomY)/2; var Zoom=(ViewW/ViewH<WidthX/HeightY)?ViewW/WidthX:ViewH/HeightY; VIEW.zoom=Zoom*0.9; VIEW.centerPoint=[CenterX,CenterY]; }; //$.writeln (SELECTION.length) |
||
回复时引用此帖 |
2024-11-16, 17:58 | 只看该作者 #2 | ||
|
|||
中级会员
等级: 七袋长老
|
请用这个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 编辑. |
||
回复时引用此帖 |
2024-11-16, 19:06 | 只看该作者 #4 | ||
|
|||
正式会员
等级: 一袋长老
|
引用:
提取出来常规单位还是PT,主要的就是改常规单位为MM |
||
回复时引用此帖 |
2024-11-16, 19:29 | 只看该作者 #5 | ||
|
|||
中级会员
等级: 六袋长老
|
引用:
var WidthX = parseFloat(((RightX - LeftX) * 0.3527777778).toFixed(2)); |
||
回复时引用此帖 |
2024-11-16, 20:29 | 只看该作者 #6 | ||
|
|||
正式会员
等级: 小兄弟
|
return value * 0.352778; // 将点转换为毫米 }); |
||
回复时引用此帖 |
2024-11-17, 14:13 | 只看该作者 #7 | ||
|
|||
正式会员
等级: 一袋长老
|
引用:
直接替换那段也不行,命令错误,可能是我不会操作 |
||
回复时引用此帖 |
2024-11-25, 11:10 | 只看该作者 #8 | |||
|
||||
中级会员
等级: 七袋长老
|
引用:
|
|||
回复时引用此帖 |