论坛帮助 |
社区圈子 |
日历事件 |
2018-11-02, 13:05 | #1 | |||
|
||||
正式会员
等级: 五袋长老
|
//作用:给定两点,新建一条直线 //参数说明 //一共五个参数 //x1,y1,x2,y2是两个点的坐标,最后个是颜色(可选项),默认是套版色 //细宽是根据当前默认值来的 //如果你知道怎么创建颜色的话,你可以把颜色传进去 addPath (0, 0, 500,500,null); function addPath(x1, y1, x2, y2,color){ var lineList = new Array(2); lineList[0] = new Point( x1, -y1); lineList[1] = new Point(x2,-y2); app.defaultStroked = true; pathRef = app.activeDocument.pathItems.add(); pathRef.setEntirePath(lineList); pathRef.stroked = true; if (color==null){ pathRef.strokeColor = app.activeDocument.swatches.getByName("[套版色]").color; }else{pathRef.strokeColor = color} return "OK"; } 为什么发这个,因为这段时间到处是求角线脚本的贴子。 各位还是画点时间研究一下吧 示例: 画一条直径,起点(0,0),终点(100,100) addPath(0,0,100,100); 如图: QQ截图20181102121132.png |
|||
右列 3 位会员因为此帖价值甚高向 五谷子 表示感谢: |
2018-11-02, 16:27 | 只看该作者 #2 | |||
|
||||
正式会员
等级: 五袋长老
|
代码:
//新建直线 //作用:给定两点,新建一条直线 //参数说明 //一共六个参数 //x1,y1,x2,y2是两个点的坐标,下一个是颜色(可选项),默认是套版色,最后一个是线宽,单位文档当前标尺单位 var myUnit = getDocUnitName(app.activeDocument); //获取当前文档标尺单位 addPath( 0, // x1 0, //y1 10, //x2 10, //y2 "CMYK 红", //色板上的名称 0.1 //描边 ); function addPath(x1, y1, x2, y2, color, width) { x1 = UnitValue(Number(x1), myUnit).as("pt"); y1 = UnitValue(Number(y1), myUnit).as("pt"); x2 = UnitValue(Number(x2), myUnit).as("pt"); y2 = UnitValue(Number(y2), myUnit).as("pt"); var lineList = new Array(2); lineList[0] = new Point(x1, -y1); lineList[1] = new Point(x2, -y2); app.defaultStroked = true; pathRef = app.activeDocument.pathItems.add(); pathRef.setEntirePath(lineList); pathRef.stroked = true; //是否描边 if (color == null) { //处理描边颜色 pathRef.strokeColor = app.activeDocument.swatches.getByName("[套版色]").color; } else { pathRef.strokeColor = app.activeDocument.swatches.getByName(color).color } if (width == null) { //处理描边宽度 pathRef.strokeWidth = 0.25; } else { pathRef.strokeWidth = UnitValue(Number(width), myUnit).as("pt"); } pathRef.filled = false; //是否填充 return "OK"; } //取得文档单位string形式 function getDocUnitName(myDoc) { var DocUnit; if (myDoc.rulerUnits == RulerUnits.Centimeters) { DocUnit = "cm" } if (myDoc.rulerUnits == RulerUnits.Inches) { DocUnit = "in" } if (myDoc.rulerUnits == RulerUnits.Millimeters) { DocUnit = "mm" } if (myDoc.rulerUnits == RulerUnits.Picas) { DocUnit = "Picas" } if (myDoc.rulerUnits == RulerUnits.Pixels) { DocUnit = "px" } if (myDoc.rulerUnits == RulerUnits.Points) { DocUnit = "pt" } if (myDoc.rulerUnits == RulerUnits.Unknown) { DocUnit = "Unknown" } return DocUnit; } |
|||