illustrator脚本 018 自动角线-1

这是一个自动加角线的脚本,来源于网络。

运行方式,先选择对象再执行脚本,无对话框。脚本不在好坏,你觉得对你有用最重要。

脚本中部分可修改选项:

//初始化自定义标线的长度,宽度,离岸,出血等参数,可自行修改
lw=0.1*2.834646; //标线宽度 0.1 mm
od=3*2.834646; //中位十字线圆形直径 3 mm
cw=15*2.834646; //智能色标的长度 15mm
ch=10*2.834646; //智能色标的高度 10mm
cspace=3*2.834646; //智能色标间隔 3mm
linelength=10*2.834646; //标注线长度 5 mm
linespace=5*2.834646; //标注线离岸 1 mm
outspace=5*2.834646; //出血 5 mm

shuangjiaoxian = true;//判断是否双脚线,属性看下面↓↓↓
rishicaiqie = false;//true开启日式标记 false关闭日式标记

doc = activeDocument;
newSpot = doc.spots[doc.spots.length-1]; //获得套版色
regColor = new SpotColor();
regColor.spot = newSpot;



theSelect = doc.selection;
lmin=theSelect[0].geometricBounds[0]; //左
tmax=theSelect[0].geometricBounds[1]; //上
lmax=theSelect[0].geometricBounds[2]; //右
tmin=theSelect[0].geometricBounds[3]; //下

//计算选择集的四边位置
for (i=1;i<theSelect.length;i++){
	if (lmin>theSelect[i].geometricBounds[0]){lmin=theSelect[i].geometricBounds[0]}
	if (tmax<theSelect[i].geometricBounds[1]){tmax=theSelect[i].geometricBounds[1]}
	if (lmax<theSelect[i].geometricBounds[2]){lmax=theSelect[i].geometricBounds[2]}
	if (tmin>theSelect[i].geometricBounds[3]){tmin=theSelect[i].geometricBounds[3]}
}

//计算所有要画的长度标线位置
w=[];
for (i=0;i<theSelect.length;i++){
	w.push(theSelect[i].geometricBounds[0]);
	w.push(theSelect[i].geometricBounds[2]);
}
if(shuangjiaoxian == true){
	//这里要加入长度标尺双脚线
	w.push(lmin-outspace);
	w.push(lmax+outspace);
	//这里结束长度标尺双脚线
}
//去除重复
ww = [];
for(var i = 0,len = w.length;i < len;i++){
	! RegExp(w[i],"g").test(ww.join(",")) && (ww.push(w[i]));
}
//构造一个数组进行去重处理
Array.prototype.indexOf = function(val) {
	for (var i = 0; i < this.length; i++) {
		if (this[i] == val)
	return i; }
return -1; };
Array.prototype.remove=function(dx) {
	if(isNaN(dx)||dx>this.length){return false;}
	for(var i=0,n=0;i<this.length;i++) {
		if(this[i]!=this[dx]){
			this[n++]=this[i]
		}
	}
	this.length-=1
}
//ai有时选择集会莫名奇妙将画布当成选择集的第一个对象,去除它
a=ww.indexOf(15279);
if (a==0){ww.remove(a);}
a=ww.indexOf(-17487);
if (a==0){ww.remove(a);}


//计算所有要画的高度标线位置
h=[];
for (i=0;i<theSelect.length;i++){
	h.push(theSelect[i].geometricBounds[1]);
	h.push(theSelect[i].geometricBounds[3]);
}
if(shuangjiaoxian == true){
	//这里要加入高度标尺双脚线
	h.push(tmax+outspace);
	h.push(tmin-outspace);
	//这里结束高度标尺双脚线
}

//去除重复
hh = [];
for(var i = 0,len = h.length;i < len;i++){
	! RegExp(h[i],"g").test(hh.join(",")) && (hh.push(h[i]));
}
//ai有时选择集会莫名奇妙将画布当成选择集的第一个对象,去除它
a=hh.indexOf( -1105);
if (a==0){hh.remove(a);}
a=hh.indexOf(31660);
if (a==0){hh.remove(a);}



//画出标线
cutlayer=doc.layers.add(); //新建图层
cutlayer.name = '切线标注层'; //设置图层名称
g = cutlayer.groupItems.add();//将标线群组,画在切线标注层上。

//画长度标线
for (i=0;i<ww.length;i++){
	line=g.pathItems.add();

	//日式裁切开始判断是否需要
	if(shuangjiaoxian == true && rishicaiqie == true && outspace == linespace){
		if(ww[i] == lmin-outspace || ww[i] == lmax+outspace){
			line.setEntirePath( [[ww[i],tmin],[ww[i],tmin-linelength-outspace]] );
			line.strokeColor= regColor;//标线使用套版色
			line.strokeWidth=lw; //指定标线宽度
			line=g.pathItems.add();
			line.setEntirePath( [[ww[i],tmax],[ww[i],tmax+linelength+outspace]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
		} else{
			line.setEntirePath( [[ww[i],tmin-linespace],[ww[i],tmin-linespace-linelength]] );
			line.strokeColor= regColor;//标线使用套版色
			line.strokeWidth=lw; //指定标线宽度
			line=g.pathItems.add();
			line.setEntirePath( [[ww[i],tmax+linespace],[ww[i],tmax+linespace+linelength]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
		}
		//日式裁切进入到这里绘制完成
	} else {
		line.setEntirePath( [[ww[i],tmin-linespace],[ww[i],tmin-linespace-linelength]] );
		line.strokeColor= regColor;//标线使用套版色
		line.strokeWidth=lw; //指定标线宽度
		line=g.pathItems.add();
		line.setEntirePath( [[ww[i],tmax+linespace],[ww[i],tmax+linespace+linelength]] );
		line.strokeColor= regColor;
		line.strokeWidth=lw;
	}}

	//画高度标线
	for (i=0;i<hh.length;i++){
		line=g.pathItems.add();
		//日式裁切开始判断是否需要
		if(shuangjiaoxian == true && rishicaiqie == true && outspace == linespace){
			if(hh[i] == tmin-outspace || hh[i] == tmax+outspace){
				line.setEntirePath( [[lmin,hh[i]],[lmin-linelength-outspace,hh[i]]] );
				line.strokeColor= regColor;
				line.strokeWidth=lw;
				line=g.pathItems.add();
				line.setEntirePath( [[lmax,hh[i]],[lmax+linelength+outspace,hh[i]]] );
				line.strokeColor= regColor;
				line.strokeWidth=lw;
				//日式裁切进入到这里绘制完成
			}else{
				line.setEntirePath( [[lmin-linespace,hh[i]],[lmin-linespace-linelength,hh[i]]] );
				line.strokeColor= regColor;
				line.strokeWidth=lw;
				line=g.pathItems.add();
				line.setEntirePath( [[lmax+linespace,hh[i]],[lmax+linespace+linelength,hh[i]]] );
				line.strokeColor= regColor;
				line.strokeWidth=lw;
			}}else {
				line.setEntirePath( [[lmin-linespace,hh[i]],[lmin-linespace-linelength,hh[i]]] );
				line.strokeColor= regColor;
				line.strokeWidth=lw;
				line=g.pathItems.add();
				line.setEntirePath( [[lmax+linespace,hh[i]],[lmax+linespace+linelength,hh[i]]] );
				line.strokeColor= regColor;
				line.strokeWidth=lw;

			}}

			//画四边的中位十字线
			line=g.pathItems.add();
			line.setEntirePath( [[lmin-linespace,tmax-(tmax-tmin)/2],[lmin-linespace-linelength,tmax-(tmax-tmin)/2]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmin-linespace-linelength/2,tmax-(tmax-tmin)/2+linelength/2],[lmin-linespace-linelength/2,tmax-(tmax-tmin)/2-linelength/2]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmax+linespace,tmax-(tmax-tmin)/2],[lmax+linespace+linelength,tmax-(tmax-tmin)/2]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmax+linespace+linelength/2,tmax-(tmax-tmin)/2+linelength/2],[lmax+linespace+linelength/2,tmax-(tmax-tmin)/2-linelength/2]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmin+(lmax-lmin)/2-linelength/2,tmax+linespace+linelength/2],[lmin+(lmax-lmin)/2+linelength/2,tmax+linespace+linelength/2]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmin+(lmax-lmin)/2,tmax+linespace],[lmin+(lmax-lmin)/2,tmax+linespace+linelength]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmin+(lmax-lmin)/2-linelength/2,tmin-linespace-linelength/2],[lmin+(lmax-lmin)/2+linelength/2,tmin-linespace-linelength/2]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;
			line=g.pathItems.add();
			line.setEntirePath( [[lmin+(lmax-lmin)/2,tmin-linespace],[lmin+(lmax-lmin)/2,tmin-linespace-linelength]] );
			line.strokeColor= regColor;
			line.strokeWidth=lw;

			//画中位十字线的圆
			o = g.pathItems.ellipse( tmax-(tmax-tmin)/2+od/2, lmin-od/2-linespace-linelength/2, od, od );line.strokeColor= regColor;
			o.strokeColor=regColor;
			o.strokeWidth=lw;
			o = g.pathItems.ellipse( tmax-(tmax-tmin)/2+od/2, lmax-od/2+linespace+linelength/2, od, od );line.strokeColor= regColor;
			o.strokeColor=regColor;
			o.strokeWidth=lw;
			o = g.pathItems.ellipse( tmax+linespace+od/2+linelength/2, lmin+(lmax-lmin)/2-od/2, od, od );line.strokeColor= regColor;
			o.strokeColor=regColor;
			o.strokeWidth=lw;
			o = g.pathItems.ellipse( tmin-linespace+od/2-linelength/2, lmin+(lmax-lmin)/2-od/2, od, od );line.strokeColor= regColor;
			o.strokeColor=regColor;
			o.strokeWidth=lw;

			//增加智能色标
			//cmyk色标
			g = cutlayer.groupItems.add();
			cColor = new CMYKColor();
			cColor.cyan = 100;
			cColor.magenta = 0;
			cColor.yellow = 0;
			cColor.black = 0;
			mColor = new CMYKColor();
			mColor.cyan = 0;
			mColor.magenta = 100;
			mColor.yellow = 0;
			mColor.black = 0;
			yColor = new CMYKColor();
			yColor.cyan = 0;
			yColor.magenta = 0;
			yColor.yellow = 100;
			yColor.black = 0;
			kColor = new CMYKColor();
			kColor.cyan = 0;
			kColor.magenta = 0;
			kColor.yellow = 0;
			kColor.black = 100;
			c = g.pathItems.rectangle( 0, (cw+cspace)*0, cw, ch );
			c.fillColor=cColor;
			c.stroked=false;
			c = g.pathItems.rectangle( 0, (cw+cspace)*1, cw, ch );
			c.fillColor=mColor;
			c.stroked=false;
			c = g.pathItems.rectangle( 0, (cw+cspace)*2, cw, ch );
			c.fillColor=yColor;
			c.stroked=false;
			c = g.pathItems.rectangle( 0, (cw+cspace)*3, cw, ch );
			c.fillColor=kColor;
			c.stroked=false;
			//专色色标
			for (i=0;i<doc.spots.length-1;i++){
				newSpot = doc.spots[i];
				regColor = new SpotColor();
				regColor.spot = newSpot;
				c = g.pathItems.rectangle( 0, (cw+cspace)*(i+4), cw, ch );
				c.fillColor=regColor;
				c.stroked=false;
			}
			g.left=lmin;
			g.top=tmin-linespace-linelength-10;

  • 6
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值