论坛帮助 |
社区圈子 |
日历事件 |
2024-06-08, 09:22 | #1 | |||
|
||||
中级会员
等级: 七袋长老
|
// 检查是否有文档打开 if (app.documents.length == 0) { alert("没有打开的文档,请打开一个文档然后重试。"); } else { var doc = app.activeDocument; var selection = doc.selection; // 检查是否有路径被选中 if (selection.length > 0 && selection[0].typename == "PathItem") { for (var i = 0; i < selection.length; i++) { var path = selection[i]; markDirection(path); } alert("标记路径方向完成!"); } else { alert("请选择至少一个路径来执行此操作。"); } } // 标记路径方向函数 function markDirection(path) { var startPoint = path.pathPoints[0].anchor; var endPoint = path.pathPoints[path.pathPoints.length - 1].anchor; var arrowhead; // 根据路径的方向确定箭头位置 if (startPoint[0] < endPoint[0] || startPoint[1] < endPoint[1]) { arrowhead = createArrowhead(endPoint, startPoint); } else { arrowhead = createArrowhead(startPoint, endPoint); } // 将箭头添加到文档中 doc.activeLayer.groupItems.add().appendItems([arrowhead]); } // 创建箭头函数 function createArrowhead(start, end) { var arrowhead = doc.groupItems.add(); var arrowWidth = 5; // 箭头宽度 var arrowLength = 10; // 箭头长度 var p1 = arrowhead.pathItems.add(); p1.setEntirePath([[end[0] - arrowLength, end[1] - arrowWidth / 2], [end[0], end[1]], [end[0] - arrowLength, end[1] + arrowWidth / 2]]); p1.closed = true; arrowhead.left = start[0]; arrowhead.top = start[1]; return arrowhead; } |
|||
回复时引用此帖 |