土品 发表于 2016-10-29 11:02:48

你看看这个怎是不是你要的自动标尺脚本

土品 发表于 2016-10-29 11:04:32

不知道怎么把脚本发出去!没看到附件上传啊

土品 发表于 2016-10-29 11:07:16

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=4;//标尺距离物体边沿宽度
asize=5;//箭头大小
if(h<50 || w<50){asize=6;}//简单的自适应,太小的物体用小箭头
tsize=6; //标尺字体大小
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 = (h/2.834645).toFixed(3)+" mm"; //小数位四舍五入取整数--------保留3位小数
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 =(w/2.834645).toFixed(3)+" 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;
}

土品 发表于 2016-10-29 11:08:25

楼主试试这个代码!不知道是不是你要的代码!

poshuixukong 发表于 2016-10-29 11:58:29

楼上这个代码有水平:)

土品 发表于 2016-10-29 22:40:13

试试这个是不是你要找的!

土品 发表于 2016-10-29 22:46:35

楼主编组的对象 视为一个对象    不是编组的对象视为多个对象! 也可以标记多个对象!

土品 发表于 2016-10-29 22:49:51

楼主   效果是这样的是不是你要的!

1139988616 发表于 2016-12-6 20:09:56

就是AI的CAD插件多得是

no543216789 发表于 2016-12-24 12:43:52

CADTool里面应该有此类功能吧
页: 1 [2] 3
查看完整版本: 求一个AI自动加尺寸的脚本源码