AI脚本建立点到点的连线教程
发布时间:2015-04-23 15:16:24 作者:佚名
我要评论
这篇教程是向脚本之家的朋友介绍AI脚本建立点到点的连线方法,教程非常不错,很值得学习,推荐到脚本之家,喜欢的朋友一起来学习吧
这篇教程像脚本之家的AI爱好者们介绍用AI脚本建立点到点的连线这个脚本是将对象上能互相连接的点做一个连接。示例如图:

连接之后类似于曼陀罗的形状。在多边形、星型或者手绘图形上也试试吧。
点最好多一些,这样能得到更好的形状;较少的点可能没有什么变化。
要用“文件-脚本”来使用,以CS3为例应放在"C:\Program Files\Adobe\Adobe Illustrator CS3\预设\脚本"下。
当然,也可以放置在其他文件夹中,通过Ctrl+F12定位到脚本所在处来使用。
复制以下全部文字到记事本中,保存为以.js结尾的脚本文件(如:脚本.js)即可。
复制代码
代码如下://///////////////////////////////////////////////////////////////
// All Points v.1.3 -- CS,CS2,CS3,CS4
//>=--------------------------------------
// This script simply draws a line from every point to every other point of your selected pathitem.
// Handy for making Mandalas. Try on polygons, stars or even freehand shapes.
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
function Loadbar(x){
this.versionNum= app.version.split(".")[0] ;
if (this.versionNum >= 13){
this.w = new Window('window', "Processing...", undefined, {independent:true});
this.w.frameLocation = [600,400];
this.w.tracker = this.w.add ('statictext' , [15,15,250,35], "processing");
this.w.prog = this.w.add ('progressbar' , [15,15,250,35], 0, x);
//this.w.show();
}
}
Loadbar.prototype.close = function(){
if (this.versionNum >= 13){
this.w.close();
}
}
Loadbar.prototype.hide=function(){
if (this.versionNum >= 13){
this.w.hide();
}
}
Loadbar.prototype.show=function(){
if (this.versionNum >= 13){
this.w.show();
}
}
Loadbar.prototype.update=function(x){
if (this.versionNum >= 13){
this.w.prog.value = x;
}
}
Loadbar.prototype.label=function(x){
if (this.versionNum >= 13){
this.w.tracker.text = x;
}
}
Array.prototype.indexOf = function(i){
var len = this.length;
for (var a=0;a{
if (this[a]==i)
{
return a;
}
return -1;
}
}
Array.prototype.man = function(test, tvars_arr, doThis, dovars_arr) {
var FUN="function";
var OBJ="object";
var UND="undefined";
var a=typeof test;
var b=typeof tvars_arr;
var c=typeof doThis;
var d=typeof dovars_arr;
// if only an array is given, it is assumed we wish to copy to it:
if (a==OBJ && tvars_arr ==undefined && doThis==undefined && dovars_arr==undefined)
{
dovars_arr = test;
test=undefined;
}
//if we just want to process all items without any testing: doThis,[dovars_arr] fun,ob
if (a==FUN && b==OBJ && doThis==undefined && dovars_arr==undefined)
{
//alert("correct");
doThis=test;
test=undefined;
dovars_arr=tvars_arr;
tvars_arr=undefined;
}else if(a==FUN && b==FUN){ // fun,fun OR fun,fun,ob
if (c==OBJ)
{
dovars_arr=doThis;
}
doThis=tvars_arr;
tvars_arr=undefined;
}
// Either case should work as normal: fun,ob,fun OR fun,ob,fun,ob
// Now set defaults if anything is missing:
test= test==undefined?AMT_exists:test;
tvars_arr= tvars_arr==undefined?[0]:tvars_arr;
doThis= doThis==undefined?AMA_exportTo:doThis;
dovars_arr= dovars_arr==undefined?[0]:dovars_arr;
//
var sl = this.length;
for (var ds = 0; ds<(sl-1); ds++) {
//first referenced function call
if (test(this[ds], tvars_arr)) {
// second referenced function call
var ret = doThis(this[ds], dovars_arr);
//change original array item if something is returned
if (ret != undefined) {
this[ds] = ret;
}
}
}
}
//DEFAULT TEST:
function AMT_exists(item, y_arr) {
//filler function for arrayMan
//always true
return 1;
}
//DEFAULT ACTION:
// exports each tested item to exp_arr
function AMA_exportTo(item, exp_arr) {
//alert(item);
exp_arr.unshift(item); //unshift because the array is being processed backwards.
}
function AMA_LinesTo(item, vars_arr) {
var count = vars_arr[0];
var group = vars_arr[1];
var src_arr = vars_arr[2];
var sal = src_arr.length;
// draw a line from this point, to every remaining point in the array
if (count == sal-1)
{
//alert("last one");
return
}
//
for (var p=(count+1);p<sal></sal>{
var myLine = drawLine(item.anchor, src_arr[p].anchor);
/* // uncomment for some fun grayscale action
var col=255/(sal/(count+1));
myLine.strokeColor.red = col;
myLine.strokeColor.green= col;
myLine.strokeColor.blue = col;
*/
b.update(p);
b.label("Item:"+(s+1)+" of "+selLen+". (node "+count+" of "+(sal-1)+")");
//redraw();
//alert("drawing count:"+count+"\nindex of "+item+" in:"+src_arr+":"+src_arr.indexOf(item));
}
vars_arr[0]++; //note: count++ doesnt work
}
function drawLine(anchor1,anchor2) {
//alert(anchor1+" and "+anchor2);
//draw a single line from point a to point b
var linePath = shapeGroup.pathItems.add();
var offset=0; // [anchor1[0]-offset,anchor1[1]-offset]
linePath.setEntirePath( Array(anchor1,anchor2) );
linePath.closed = false;
linePath.stroked = true;
linePath.filled = false;
linePath.strokeWidth = 1;
return linePath;
}
//----------------main
alert0="请打开一个文档";
alert1="只能对单一对象生效!\n不能是剪切蒙版、复合路径、复合形状、群组等!";
if ( app.documents.length == 0 ) {
alert(alert0);
}else if (app.activeDocument.selection.length == 0){
alert(alert1);
}else if (app.activeDocument.selection[0].typename != "PathItem"){
alert(alert1);
}else{
doc=activeDocument;
sel=doc.selection;
selLen=sel.length;
// walk through each selected item
for (var s=0;s<sellen></sellen>{
if (sel[s].typename == "PathItem")
{
var b = new Loadbar(sel[s].selectedPathPoints.length);
b.show();
var obj = sel[s];
var src_arr = obj.selectedPathPoints;
var count = 0;
var shapeGroup = app.activeDocument.groupItems.add();
src_arr.man(AMA_LinesTo,[count,shapeGroup,src_arr]);
b.close();
}
}
}
// All Points v.1.3 -- CS,CS2,CS3,CS4
//>=--------------------------------------
// This script simply draws a line from every point to every other point of your selected pathitem.
// Handy for making Mandalas. Try on polygons, stars or even freehand shapes.
//>=--------------------------------------
// JS code (c) copyright: John Wundes ( john@wundes.com ) www.wundes.com
//copyright full text here: http://www.wundes.com/js4ai/copyright.txt
//////////////////////////////////////////////////////////////////
function Loadbar(x){
this.versionNum= app.version.split(".")[0] ;
if (this.versionNum >= 13){
this.w = new Window('window', "Processing...", undefined, {independent:true});
this.w.frameLocation = [600,400];
this.w.tracker = this.w.add ('statictext' , [15,15,250,35], "processing");
this.w.prog = this.w.add ('progressbar' , [15,15,250,35], 0, x);
//this.w.show();
}
}
Loadbar.prototype.close = function(){
if (this.versionNum >= 13){
this.w.close();
}
}
Loadbar.prototype.hide=function(){
if (this.versionNum >= 13){
this.w.hide();
}
}
Loadbar.prototype.show=function(){
if (this.versionNum >= 13){
this.w.show();
}
}
Loadbar.prototype.update=function(x){
if (this.versionNum >= 13){
this.w.prog.value = x;
}
}
Loadbar.prototype.label=function(x){
if (this.versionNum >= 13){
this.w.tracker.text = x;
}
}
Array.prototype.indexOf = function(i){
var len = this.length;
for (var a=0;a{
if (this[a]==i)
{
return a;
}
return -1;
}
}
Array.prototype.man = function(test, tvars_arr, doThis, dovars_arr) {
var FUN="function";
var OBJ="object";
var UND="undefined";
var a=typeof test;
var b=typeof tvars_arr;
var c=typeof doThis;
var d=typeof dovars_arr;
// if only an array is given, it is assumed we wish to copy to it:
if (a==OBJ && tvars_arr ==undefined && doThis==undefined && dovars_arr==undefined)
{
dovars_arr = test;
test=undefined;
}
//if we just want to process all items without any testing: doThis,[dovars_arr] fun,ob
if (a==FUN && b==OBJ && doThis==undefined && dovars_arr==undefined)
{
//alert("correct");
doThis=test;
test=undefined;
dovars_arr=tvars_arr;
tvars_arr=undefined;
}else if(a==FUN && b==FUN){ // fun,fun OR fun,fun,ob
if (c==OBJ)
{
dovars_arr=doThis;
}
doThis=tvars_arr;
tvars_arr=undefined;
}
// Either case should work as normal: fun,ob,fun OR fun,ob,fun,ob
// Now set defaults if anything is missing:
test= test==undefined?AMT_exists:test;
tvars_arr= tvars_arr==undefined?[0]:tvars_arr;
doThis= doThis==undefined?AMA_exportTo:doThis;
dovars_arr= dovars_arr==undefined?[0]:dovars_arr;
//
var sl = this.length;
for (var ds = 0; ds<(sl-1); ds++) {
//first referenced function call
if (test(this[ds], tvars_arr)) {
// second referenced function call
var ret = doThis(this[ds], dovars_arr);
//change original array item if something is returned
if (ret != undefined) {
this[ds] = ret;
}
}
}
}
//DEFAULT TEST:
function AMT_exists(item, y_arr) {
//filler function for arrayMan
//always true
return 1;
}
//DEFAULT ACTION:
// exports each tested item to exp_arr
function AMA_exportTo(item, exp_arr) {
//alert(item);
exp_arr.unshift(item); //unshift because the array is being processed backwards.
}
function AMA_LinesTo(item, vars_arr) {
var count = vars_arr[0];
var group = vars_arr[1];
var src_arr = vars_arr[2];
var sal = src_arr.length;
// draw a line from this point, to every remaining point in the array
if (count == sal-1)
{
//alert("last one");
return
}
//
for (var p=(count+1);p<sal></sal>{
var myLine = drawLine(item.anchor, src_arr[p].anchor);
/* // uncomment for some fun grayscale action
var col=255/(sal/(count+1));
myLine.strokeColor.red = col;
myLine.strokeColor.green= col;
myLine.strokeColor.blue = col;
*/
b.update(p);
b.label("Item:"+(s+1)+" of "+selLen+". (node "+count+" of "+(sal-1)+")");
//redraw();
//alert("drawing count:"+count+"\nindex of "+item+" in:"+src_arr+":"+src_arr.indexOf(item));
}
vars_arr[0]++; //note: count++ doesnt work
}
function drawLine(anchor1,anchor2) {
//alert(anchor1+" and "+anchor2);
//draw a single line from point a to point b
var linePath = shapeGroup.pathItems.add();
var offset=0; // [anchor1[0]-offset,anchor1[1]-offset]
linePath.setEntirePath( Array(anchor1,anchor2) );
linePath.closed = false;
linePath.stroked = true;
linePath.filled = false;
linePath.strokeWidth = 1;
return linePath;
}
//----------------main
alert0="请打开一个文档";
alert1="只能对单一对象生效!\n不能是剪切蒙版、复合路径、复合形状、群组等!";
if ( app.documents.length == 0 ) {
alert(alert0);
}else if (app.activeDocument.selection.length == 0){
alert(alert1);
}else if (app.activeDocument.selection[0].typename != "PathItem"){
alert(alert1);
}else{
doc=activeDocument;
sel=doc.selection;
selLen=sel.length;
// walk through each selected item
for (var s=0;s<sellen></sellen>{
if (sel[s].typename == "PathItem")
{
var b = new Loadbar(sel[s].selectedPathPoints.length);
b.show();
var obj = sel[s];
var src_arr = obj.selectedPathPoints;
var count = 0;
var shapeGroup = app.activeDocument.groupItems.add();
src_arr.man(AMA_LinesTo,[count,shapeGroup,src_arr]);
b.close();
}
}
}
相关文章

ai怎么混合两种颜色? illustrator混合两个色块的颜色的方法
ai填充不同颜色的图形重叠以后,想要将两种颜色混合,该怎么混合颜色呢?下面我们就来看看详细的教程2024-07-18
ai网格线间距默认的不是很喜欢,想要自己调整一下,该怎么调整呢?今天我们就来看看参考线调整技巧2024-05-28
ai路径平均效果怎么用? illustrator使用平均路径的教程
Adobe Illustrator中有一个路径平均功能,如何使用呢?下面小编为大家演示路径平均功能的一种使用方法2024-05-21
ai保存pdf格式出现多余内容怎么解决? 去掉pdf文件多余内容的技巧
ai保存pdf格式出现多余内容怎么解决?ai中的文档保存为pdf文件的时候,发现有多余内容,该怎么操作呢?下面我们就来看看去掉pdf文件多余内容的技巧2023-12-19
ai描边在哪里?ai中想要设置描边,该怎么操作呢?下面我们就来看看ai设置描边的多种方法2023-12-19
ai原位复制怎么用?复制图形的时候,想要原位复制粘贴,该怎么操作呢?下面我们就来看看ai原位复制快捷键介绍2023-12-19
ai怎么让文字随着路径变形? illustrator区域文字不跟着变换方向问题的
ai怎么让文字随着路径变形?选中文字后,发现文字不跟随变换区域旋转该怎么办呢?下面我们就来看看illustrator区域文字不跟着变换问题的解决办法2023-11-30
ai渐变色怎么调方向? illustrator将渐变颜色反向的技巧
ai渐变色怎么调方向?ai中给图形填渐变色,想要进行反向,该怎么操作呢?下面我们就来看看illustrator将渐变颜色反向的技巧2023-11-30
Ai彩色logo怎么做反白反黑效果? ai彩色logo转化为黑白稿的技巧
Ai彩色logo怎么做反白反黑效果?设计的彩色logo想要做黑白稿,就是反黑反白效果,下面我们就来看看ai彩色logo转化为黑白稿的技巧2023-11-12
ai怎么设计迷宫字体效果?我们需要使用分割网格结合形状生成器工具,制作迷宫字体,下面我们就来看看详细的设计过程2023-11-02






最新评论