论坛帮助 |
社区圈子 |
日历事件 |
2020-10-08, 17:48 | #1 | ||
|
|||
见习会员
等级: 小兄弟
|
AI对于我们服装来说,太多太强大了,我们能用的功能不多,就那么几个。几个常用功能还受益于坛子里大佬的脚本,可以省下很多事情。感谢大家的无私分享!! 我个人用得最多得就是江门蒋基雄大大的尺寸标注脚本。非常感谢您的无私分享。感激之情无以言表。想去挖坟2015年原始的帖子去发表回复表达感激都被禁止回复,不得已,开了新贴。 用得多了,总会有更多的不满足,这不,这个脚本以前是左边和下面标注尺寸。现今我想改到右边和下面标注尺寸却无从下手了。希望能体谅我们这种完全看不懂脚本小白的冒昧,希望有幸得大家指点 再次,感谢江门蒋基雄大大!感谢大家! —————————————————————————————————————————— 源代码版权属于: https://www.cnprint.org 江门蒋基雄 xpmycpc 进行了其中部分的修改。 1.修正,描边情况下显示不准的情况 2.修正,显示小数,保留1位。 */ var doc = app.activeDocument; var u=72.0000084; var theSelect = doc.selection; var s=12;//标尺距离物体边沿宽度 var tsize=72; //标尺字体大小 // spec layer try { var sizelayer =doc.layers['spec']; } catch(err) { var sizelayer = doc.layers.add(); sizelayer.name = 'spec'; } doc.selection = null; // 还原选择的图案为系统默认 doc.defaultFilled = false; doc.defaultStroked = true; doc.defaultStrokeWidth = 5; // 线的粗细 doc.defaultStrokeColor = redColor(); function redColor(){ redColor = new CMYKColor(); redColor.black = 0;//这里可修改四色的黑版值 redColor.cyan = 00;//这里可修改四色的蓝版值 redColor.magenta =100;//这里可修改四色的洋红版值 redColor.yellow = 100;//这里可修改四色的黄版值 return redColor; } for (i=0;i<theSelect.length;i++){ //加入批处理 sW=(theSelect[i]=='[PathItem ]' && theSelect[i].stroked==true)?theSelect[i].strokeWidth:0; x=theSelect[i].left; y=theSelect[i].top; w=theSelect[i].width+sW; h=theSelect[i].height+sW; var asize=12;//箭头大小 if(h<5 || w<5){asize=50;};//简单的自适应,太小的物体用小箭头 //var g1 = doc.groupItems.add();将标尺群组 var g1 = sizelayer.groupItems.add();//将标尺群组,将标注画在标注图层上。 var line1=g1.pathItems.add(); //画高度标尺 line1.setEntirePath( [[x-s, y],[x-s, y-h]]) ; var line1=g1.pathItems.add(); line1.setEntirePath( [[x-s-s/2, y],[x-s/2, y]]) ; var line1=g1.pathItems.add(); line1.setEntirePath( [[x-s-s/2, y-h],[x-s/2, y-h]]) ; var ar1=g1.pathItems.add(); //画箭头 ar1.stroked=false; ar1.fillColor= redColor(); ar1.setEntirePath( [[x-s, y],[x-s-asize/2,y-asize],[x-s+asize/2,y-asize]]) ; ar1.closed=true var ar1=g1.pathItems.add(); ar1.stroked=false; ar1.fillColor= redColor(); ar1.setEntirePath( [[x-s, y-h],[x-s-asize/2,y-h+asize],[x-s+asize/2,y-h+asize]]) ; ar1.closed=true var t1 = g1.textFrames.add(); t1.contents = (h/u).toFixed(2)+" ”"; //小数位四舍五入取整数''可加单位mm Math.round(h/u).toFixed(0)/多少位小数点 t1.textRange.characterAttributes.size=tsize; t1.textRange.characterAttributes.fillColor= redColor(); t1.textRange.textFont=app.textFonts[textFonts.name="MyriadPro-Bold"];//字型:微软雅黑 t1.left = x-s-s-t1.width; t1.top = y-h/2+t1.height/2; var line2=g1.pathItems.add(); //画长度标尺 line2.setEntirePath( [[x, y-h-s],[x+w, y-h-s]]) ; var line2=g1.pathItems.add(); line2.setEntirePath( [[x, y-h-s-s/2],[x, y-h-s/2]]) ; var line2=g1.pathItems.add(); line2.setEntirePath( [[x+w, y-h-s-s/2],[x+w, y-h-s/2]]) ; var ar1=g1.pathItems.add(); //画箭头 ar1.stroked= false; ar1.fillColor= redColor(); ar1.setEntirePath( [[x,y-h-s],[x+asize,y-h-s-asize/2],[x+asize,y-h-s+asize/2]]) ; ar1.closed=true var ar1=g1.pathItems.add(); ar1.stroked= false; ar1.fillColor= redColor(); ar1.setEntirePath( [[x+w,y-h-s],[x+w-asize,y-h-s-asize/2],[x+w-asize,y-h-s+asize/2]]) ; ar1.closed=true var t2 = g1.textFrames.add(); t2.contents = (w/u).toFixed(2)+" ”"; //小数位四舍五入取整数''可加单位mm t2.textRange.characterAttributes.size=tsize; t2.textRange.characterAttributes.fillColor= redColor(); t2.textRange.textFont=app.textFonts[textFonts.name="MyriadPro-Bold"];//字型:微软雅黑 t2.left = x+w/2-t2.width/2; t2.top = y-h-s-s; } |
||
2020-10-08, 17:54 | 只看该作者 #2 | ||
|
|||
见习会员
等级: 小兄弟
|
—————————————————————————————————————————————————————————————————————————————————————————————————— /* * Description: An Adobe Illustrator script that automates measurements of objects. This is an early version that has not been sufficiently tested. Use at your own risks. * Usage: Select 1 to 2 page items in Adobe Illustrator, then run this script by selecting File > Script > Other Scripts > (choose file) * License: GNU General Public License Version 3. (http://www.gnu.org/licenses/gpl-3.0-standalone.html) * * Copyright (c) 2009. William Ngan. * http://www.metaphorical.net */ // Create an empty dialog window near the upper left of the screen var dlg = new Window('dialog', 'Spec'); dlg.frameLocation = [100,100]; dlg.size = [250,250]; dlg.intro = dlg.add('statictext', [20,20,150,40] ); dlg.intro.text = 'First select 1 or 2 items'; dlg.where = dlg.add('dropdownlist', [20,40,150,60] ); dlg.where.selection = dlg.where.add('item', 'top'); dlg.where.add('item', 'bottom'); dlg.where.add('item', 'left'); dlg.where.add('item', 'right'); dlg.btn = dlg.add('button', [20,70,150,90], 'Specify', 'spec'); // document var doc = activeDocument; // spec layer try { var speclayer =doc.layers['spec']; } catch(err) { var speclayer = doc.layers.add(); speclayer.name = 'spec'; } // measurement line color var color = new RGBColor; color.green = 255; color.blue = 0; // gap between measurement lines and object var gap = 2; // size of measurement lines. var size = 10; // number of decimal places var decimals = 0; // pixels per inch var dpi = 72; /** Start the spec */ function startSpec() { if (doc.selection.length==1) { specSingle( doc.selection[0].geometricBounds, dlg.where.selection.text ); } else if (doc.selection.length==2) { specDouble( doc.selection[0], doc.selection[1], dlg.where.selection.text ); } else { alert('please select 1 or 2 items'); } dlg.close (); } /** Spec the gap between 2 elements */ function specDouble( item1, item2, where ) { var bound = new Array(0,0,0,0); var a = item1.geometricBounds; var b = item2.geometricBounds; if (where=='top' || where=='bottom') { if (b[0]>a[0]) { // item 2 on right, if (b[0]>a[2]) { // no overlap bound[0] =a[2]; bound[2] = b[0]; } else { // overlap bound[0] =b[0]; bound[2] = a[2]; } } else if (a[0]>=b[0]){ // item 1 on right if (a[0]>b[2]) { // no overlap bound[0] =b[2]; bound[2] = a[0]; } else { // overlap bound[0] =a[0]; bound[2] = b[2]; } } bound[1] = Math.max (a[1], b[1]); bound[3] = Math.min (a[3], b[3]); } else { if (b[3]>a[3]) { // item 2 on top if (b[3]>a[1]) { // no overlap bound[3] =a[1]; bound[1] = b[3]; } else { // overlap bound[3] =b[3]; bound[1] = a[1]; } } else if (a[3]>=b[3]){ // item 1 on top if (a[3]>b[1]) { // no overlap bound[3] =b[1]; bound[1] = a[3]; } else { // overlap bound[3] =a[3]; bound[1] = b[1]; } } bound[0] = Math.min(a[0], b[0]); bound[2] = Math.max (a[2], b[2]); } specSingle(bound, where ); } /** spec a single object [MENTION=343005]para[/MENTION]m bound item.geometricBound [MENTION=343005]para[/MENTION]m where 'top', 'bottom', 'left,' 'right' */ function specSingle( bound, where ) { // width and height var w = bound[2]-bound[0]; var h = bound[1]-bound[3]; // a & b are the horizontal or vertical positions that change // c is the horizontal or vertical position that doesn't change var a = bound[0]; var b = bound[2]; var c = bound[1]; // xy='x' (horizontal measurement), xy='y' (vertical measurement) var xy = 'x'; // a direction flag for placing the measurement lines. var dir = 1; switch( where ) { case 'top': a = bound[0]; b = bound[2]; c = bound[1]; xy = 'x'; dir = 1; break; case 'bottom': a = bound[0]; b = bound[2]; c = bound[3]; xy = 'x'; dir = -1; break; case 'left': a = bound[1]; b = bound[3]; c = bound[0]; xy = 'y'; dir = -1; break; case 'right': a = bound[1]; b = bound[3]; c = bound[2]; xy = 'y'; dir = 1; break; } // create the measurement lines var lines = new Array(); // horizontal measurement if (xy=='x') { // 2 vertical lines lines[0]= new Array( new Array(a, c+(gap)*dir) ); lines[0].push ( new Array(a, c+(gap+size)*dir) ); lines[1]= new Array( new Array(b, c+(gap)*dir) ); lines[1].push( new Array(b, c+(gap+size)*dir) ); // 1 horizontal line lines[2]= new Array( new Array(a, c+(gap+size/2)*dir ) ); lines[2].push( new Array(b, c+(gap+size/2)*dir ) ); // create text label if (where=='top') { var t = specLabel( w, (a+b)/2, lines[0][1][1] ); t.top += t.height; } else { var t = specLabel( w, (a+b)/2, lines[0][0][1] ); t.top -= t.height; } t.left -= t.width/2; // vertical measurement } else { // 2 horizontal lines lines[0]= new Array( new Array( c+(gap)*dir, a) ); lines[0].push ( new Array( c+(gap+size)*dir, a) ); lines[1]= new Array( new Array( c+(gap)*dir, b) ); lines[1].push( new Array( c+(gap+size)*dir, b) ); //1 vertical line lines[2]= new Array( new Array(c+(gap+size/2)*dir, a) ); lines[2].push( new Array(c+(gap+size/2)*dir, b) ); // create text label if (where=='left') { var t = specLabel( h, lines[0][1][0], (a+b)/2 ); t.left -= t.width; } else { var t = specLabel( h, lines[0][0][0], (a+b)/2 ); t.left += size; } t.top += t.height/2; } // draw the lines var specgroup = new Array(t); for (var i=0; i<lines.length; i++) { var p = doc.pathItems.add(); p.setEntirePath ( lines[i] ); setLineStyle( p, color ); specgroup.push( p ); } group(speclayer, specgroup ); } /** Create a text label that specify the dimension */ function specLabel( val, x, y) { var t = doc.textFrames.add(); t.textRange.characterAttributes.size = 8; t.textRange.characterAttributes.alignment = StyleRunAlignmentType.center; var v = val; switch (doc.rulerUnits) { case RulerUnits.Inches: v = val/dpi; v = v.toFixed (decimals); break; case RulerUnits.Centimeters: v = val/(dpi/2.54); v = v.toFixed (decimals); break; case RulerUnits.Millimeters: v = val/(dpi/25.4); v = v.toFixed (decimals); break; case RulerUnits.Picas: v = val/(dpi/6); var vd = v - Math.floor (v); vd = 12*vd; v = Math.floor(v)+'p'+vd.toFixed (decimals); break; default: v = v.toFixed (decimals); } t.contents = v; t.top = y; t.left = x; return t; } function setLineStyle(path, color) { path.filled = false; path.stroked = true; path.strokeColor = color; path.strokeWidth = 0.5; return path; } /** * Group items in a layer */ function group( layer, items, isDuplicate) { // create new group var gg = layer.groupItems.add(); // add to group // reverse count, because items length is reduced as items are moved to new group for(var i=items.length-1; i>=0; i--) { if (items[i]!=gg) { // don't group the group itself if (isDuplicate) { newItem = items[i].duplicate (gg, ElementPlacement.PLACEATBEGINNING); } else { items[i].move( gg, ElementPlacement.PLACEATBEGINNING ); } } } return gg; } // ---------------------------------------------------------------------------------------------------------------------------------------- dlg.btn.addEventListener ('click', startSpec ); dlg.show(); |
||