冰晶 发表于 2016-7-25 10:37:11

求一个AI自动加尺寸的脚本源码

全选所有方方圆圆的东西加在下面如图

3542901277 发表于 2016-7-25 10:37:12

用法:选择要标注的物体,可选多个,运行本脚本就自动标注尺寸,群组对象视为一个物体


doc = app.activeDocument;
theSelect = doc.selection;
for (i=0;i<theSelect.length;i++){ //批处理多个选择物体
x=theSelect.left;
y=theSelect.top;
w=theSelect.width;
h=theSelect.height;
s=60;//标尺距离物体边沿宽度
asize=20;//箭头大小
if(h<50 || w<50){asize=10;}//简单的自适应,太小的物体用小箭头
tsize=40; //标尺字体大小
redColor = new CMYKColor();//标尺用红色
redColor.black = 00;
redColor.cyan = 0;
redColor.magenta =100;
redColor.yellow = 100;
var g1 = doc.groupItems.add();//将标尺群组
var line1=g1.pathItems.add(); //画高度标尺
line1.setEntirePath( new Array(
new Array(x-s, y),
new Array(x-s, y-h),
)
) ;
line1.strokeColor= redColor;
var line1=g1.pathItems.add();
line1.setEntirePath( new Array(
new Array(x-s-s/2, y),
new Array(x-s/2, y),
)
) ;
line1.strokeColor= redColor;
var line1=g1.pathItems.add();
line1.setEntirePath( new Array(
new Array(x-s-s/2, y-h),
new Array(x-s/2, y-h),
)
) ;
line1.strokeColor= redColor;
//画箭头
var ar1=g1.pathItems.add();
ar1.setEntirePath( new Array(
new Array(x-s, y),
new Array(x-s-asize/2,y-asize),
new Array(x-s+asize/2,y-asize),
)
) ;
ar1.strokeColor= NoColor;
ar1.fillColor= redColor;
ar1.closed=true;
var ar1=g1.pathItems.add();
ar1.setEntirePath( new Array(
new Array(x-s, y-h),
new Array(x-s-asize/2,y-h+asize),
new Array(x-s+asize/2,y-h+asize),
)
) ;
ar1.strokeColor= NoColor;
ar1.fillColor= redColor;
ar1.closed=true;
var t1 = g1.textFrames.add();
t1.contents = Math.round(h*0.35277778)+" mm"; //小数位四舍五入取整数
t1.textRange.characterAttributes.size=tsize;
t1.textRange.characterAttributes.fillColor= redColor;
t1.left = x-s-s-t1.width;
t1.top = y-h/2+t1.height/2;
var line2=g1.pathItems.add(); //画长度标尺
line2.setEntirePath( new Array(
new Array(x, y-h-s),
new Array(x+w, y-h-s),
)
) ;
line2.strokeColor= redColor;
var line2=g1.pathItems.add();
line2.setEntirePath( new Array(
new Array(x, y-h-s-s/2),
new Array(x, y-h-s/2),
)
) ;
line2.strokeColor= redColor;
var line2=g1.pathItems.add();
line2.setEntirePath( new Array(
new Array(x+w, y-h-s-s/2),
new Array(x+w, y-h-s/2),
)
) ;
line2.strokeColor= redColor;
//画箭头
var ar1=g1.pathItems.add();
ar1.setEntirePath( new Array(
new Array(x,y-h-s),
new Array(x+asize,y-h-s-asize/2),
new Array(x+asize,y-h-s+asize/2),
)
) ;
ar1.strokeColor= NoColor;
ar1.fillColor= redColor;
ar1.closed=true;
var ar1=g1.pathItems.add();
ar1.setEntirePath( new Array(
new Array(x+w,y-h-s),
new Array(x+w-asize,y-h-s-asize/2),
new Array(x+w-asize,y-h-s+asize/2),
)
) ;
ar1.strokeColor= NoColor;
ar1.fillColor= redColor;
ar1.closed=true;

var t2 = g1.textFrames.add();
t2.contents = Math.round(w*0.35277778)+" mm"; //小数位四舍五入取整数
t2.textRange.characterAttributes.size=tsize;
t2.textRange.characterAttributes.fillColor= redColor;
t2.left = x+w/2-t2.width/2;
t2.top = y-h-s-s;
}

bantwo 发表于 2016-7-25 10:57:25

好像没看过这种AI脚本:Q

冰晶 发表于 2016-7-25 10:58:14

bantwo 发表于 2016-7-25 10:57
好像没看过这种AI脚本

{:1_133:}每次看到你头像我脸疼啊

bantwo 发表于 2016-7-25 11:05:02

冰晶 发表于 2016-7-25 10:58
每次看到你头像我脸疼啊

是 吗哈哈哈{:1_94:}

amwypm3974 发表于 2016-8-5 14:06:38

franciscuswang 发表于 2016-8-19 18:01:36

本帖最后由 franciscuswang 于 2016-8-19 18:02 编辑

试试这个AI自动加尺寸的脚本,
选择一个对象,然后运行该脚本,确认测量的方向。这将指定对象的宽度或高度。选择两个对象并运行该脚本。这将指定两个对象之间的水平或垂直间隙。如果将几个对象和运行脚本,你会得到组对象的大小。

冰晶 发表于 2016-8-19 18:33:21

franciscuswang 发表于 2016-8-19 18:01
试试这个AI自动加尺寸的脚本,
选择一个对象,然后运行该脚本,确认测量的方向。这将指定对象的宽度或高度 ...

这个哪里都有 我不需要这个 我只要我那样子的

土品 发表于 2016-10-25 15:27:30

同求我也一直在找这个麻烦楼主 找到了分享一下

刻舟 发表于 2016-10-25 19:25:39

没这方面的需求,有时用CAD插件拉一下长宽,这种我一直用手打:)
页: [1] 2 3
查看完整版本: 求一个AI自动加尺寸的脚本源码