注册 登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

老胤祥 YOU CAN, DO IT!

Illustrator CS6/CC 插件 脚本 动作 笔刷 符号 教程

 
 
 

日志

 
 

ScriptUI Graphics Display 在脚本窗口里预览图形 112  

2016-05-26 21:09:24|  分类: AI 脚本 Scripts |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
  1. // ScriptUI Graphics Display by Vasily  
  2.   
  3.   
  4. function graphicsDisplay(){  
  5.     function itemShape(myShape){  
  6.         // Going to test for circles.  
  7.         var shapeKind={  
  8.             isrectangle: null,  
  9.             iscircle: null,  
  10.             isellipse: null  
  11.         };  
  12.         if(myShape.typename=='PathItem' && myShape.pathPoints.length == 4){ // RECTANGLE CHECKER  
  13.             //--------------------2 diagonals-------------------------  
  14.             var recEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +  
  15.             Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2)); // diagonal  
  16.             var recEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +  
  17.             Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2)); // diagonal  
  18.             //---------------------4 sides of rectangle---------------  
  19.             var sideA = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[1].anchor[0]),2) +  
  20.             Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[1].anchor[1]),2));    
  21.             var sideB = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +  
  22.             Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[2].anchor[1]),2));    
  23.             var sideC = parseInt(Math.pow((myShape.pathPoints[2].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +  
  24.             Math.pow((myShape.pathPoints[2].anchor[1] - myShape.pathPoints[3].anchor[1]),2));    
  25.             var sideD = parseInt(Math.pow((myShape.pathPoints[3].anchor[0] - myShape.pathPoints[0].anchor[0]),2) +  
  26.             Math.pow((myShape.pathPoints[3].anchor[1] - myShape.pathPoints[0].anchor[1]),2));    
  27.             if(recEquaDistOne == recEquaDistTwo){ // If two diagonals connecting opposite points are same length, it's a 90 degree box                  
  28.                 if((sideA == sideC) && (sideB == sideD)){  
  29.                     for(var j=0; j<4; j++){  
  30.                         var point = myShape.pathPoints[j];                
  31.                             if((point.leftDirection[0] == point.anchor[0]) &&  
  32.                                 (point.anchor[0] == point.rightDirection[0]) &&  
  33.                                 (point.leftDirection[1] == point.anchor[1]) &&  
  34.                                 (point.anchor[1] == point.rightDirection[1])){                                                      
  35.                                 shapeKind.isrectangle = true;   
  36.                             } else {  
  37.                                 shapeKind.isrectangle = false;  
  38.                                 break;  
  39.                             }  
  40.                         }  
  41.                     }  
  42.                 }  
  43.             }  
  44.             if(myShape.pathPoints.length == 4){  // CIRCLE CHECKER  
  45.                 if(shapeKind.isrectangle == false || shapeKind.isrectangle == null){  
  46.                     var circlePts = new Array();  
  47.                     var circleSlopes = new Array();  
  48.                     for (k=0; k<4; k++){  
  49.                     var point = myShape.pathPoints[k];    
  50.                     var leftHandleDist = parseInt(Math.pow((point.leftDirection[0] - point.anchor[0]),2) +  
  51.                     Math.pow((point.leftDirection[1] - point.anchor[1]),2));   
  52.                     var rightHandleDist = parseInt(Math.pow((point.rightDirection[0] - point.anchor[0]),2) +  
  53.                     Math.pow((point.rightDirection[1] - point.anchor[1]),2));  
  54.                     circlePts.push(leftHandleDist, rightHandleDist);  
  55.                     var leftHandleSlope = ((point.leftDirection[0] - point.anchor[0])/(point.leftDirection[1] - point.anchor[1])).toFixed(2);  
  56.                     var rightHandleSlope = ((point.rightDirection[0] - point.anchor[0])/(point.rightDirection[1] - point.anchor[1])).toFixed(2);  
  57.                     circleSlopes.push(leftHandleSlope, rightHandleSlope);  
  58.                 }  
  59.                 for(var f=0; f<8; f++){ // Allows non-rotated circles.  
  60.                     if(circleSlopes[f] == "-0.00"){  
  61.                         circleSlopes[f] = "0.00";  
  62.                     }  
  63.                     if(circleSlopes[f] == "-Infinity"){  
  64.                         circleSlopes[f] = "Infinity";  
  65.                     }  
  66.                 }  
  67.                 var cirEquaDistOne = parseInt(Math.pow((myShape.pathPoints[0].anchor[0] - myShape.pathPoints[2].anchor[0]),2) +  
  68.                 Math.pow((myShape.pathPoints[0].anchor[1] - myShape.pathPoints[2].anchor[1]),2));  
  69.                 var cirEquaDistTwo = parseInt(Math.pow((myShape.pathPoints[1].anchor[0] - myShape.pathPoints[3].anchor[0]),2) +  
  70.                 Math.pow((myShape.pathPoints[1].anchor[1] - myShape.pathPoints[3].anchor[1]),2));  
  71.                 if(circleSlopes[0] != "NaN"){ // Filters out asymmetric rhombus  <><><>^^^^^^<><><>  
  72.                     if((circlePts[0] == circlePts[1]) && // Filters out shapes with control handles not of equal distance from anchor point.  
  73.                         (circlePts[1] == circlePts[2]) &&  
  74.                         (circlePts[2] == circlePts[3]) &&  
  75.                         (circlePts[3] == circlePts[4]) &&  
  76.                         (circlePts[4] == circlePts[5]) &&  
  77.                         (circlePts[5] == circlePts[6]) &&  
  78.                         (circlePts[6] == circlePts[7]) &&  
  79.                         (circlePts[7] == circlePts[0])){  
  80.                         if((circleSlopes[0] == circleSlopes[1]) && // Filters out the equadistant 4-pointed Star shape (dismisses negative slopes).  
  81.                             (circleSlopes[2] == circleSlopes[3]) &&  
  82.                             (circleSlopes[4] == circleSlopes[5]) &&  
  83.                             (circleSlopes[6] == circleSlopes[7])){  
  84.                             if(cirEquaDistOne == cirEquaDistTwo){ // Filters out Ellipses (non-equadistant circles).  
  85.                                 // Filters out the very RARE 4-pointed star which has all control points in its center on top of each other!  
  86.                                 if(((myShape.pathPoints[0].leftDirection[0]).toFixed(2) != (myShape.pathPoints[1].leftDirection[0]).toFixed(2)) &&  
  87.                                     ((myShape.pathPoints[0].leftDirection[1]).toFixed(2) != (myShape.pathPoints[1].leftDirection[1]).toFixed(2))){  
  88.                                     shapeKind.iscircle = true;  
  89.                                 } else {  
  90.                                     shapeKind.iscircle = false;  
  91.                                 }  
  92.                             }  
  93.                         }  
  94.                     } else {  
  95.                         if((circlePts[0]==circlePts[1]) &&  
  96.                             (circlePts[2]==circlePts[3]) &&  
  97.                             ((circlePts[4]==circlePts[5]) && (circlePts[4]==circlePts[1]) && (circlePts[5]==circlePts[1])) &&  
  98.                             ((circlePts[6]==circlePts[7]) && (circlePts[6]==circlePts[2]) && (circlePts[7]==circlePts[3]))){  
  99.                             shapeKind.isellipse=true;  
  100.                         }  
  101.     //~                     $.writeln(circlePts[0]+'\r'+circlePts[1]+'\r'+circlePts[2]+'\r'+circlePts[3]+'\r'+  
  102.     //~                     circlePts[4]+'\r'+circlePts[5]+'\r'+circlePts[6]+'\r'+circlePts[7]);  
  103.                     }  
  104.                 }  
  105.             }  
  106.         }  
  107.         return shapeKind;  
  108.     }  
  109.     if(app.name=='Adobe Illustrator' && app.documents.length>0){  
  110.         function round2(num){  
  111.             return Math.round(num*100)/100;  


  1.   
  2.   
  3. graphicsDisplay();  

Biohaz Drawing.JPGBiohaz Drawing-scriptUI.JPGBiohaz Drawing-scriptUI-result.JPG

脚本下载地址:http://fun.ctfile.com/info/wg5132043

  评论这张
 
阅读(121)| 评论(0)
推荐 转载

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018