var doc = app.activeDocument;
var stringBuild = '';
var pt = 72/25.4;
for ( j = 0; j <doc.pathItems.length; j++ ) {
try {
var a = doc.pathItems[j];
ac=a.fillColor.cyan;
am=a.fillColor.magenta ;
ay=a.fillColor.yellow;
ak=a.fillColor.black;
var x = a.left;
var y = a.top;
var w = a.width;
var h = a.height;
if(ac==0&&am==0&&Math.abs(ay-1)<0.01&&ak==0){
var index = 0
for(var ai=0;ai<doc.artboards.length;ai++){
var d = isIn(ai,a)
if(d!=undefined){
index= ai+1
x= d['x']
y= d['y']
break;
}
}
stringBuild += 'index:'+ index+
",x:" + (x/pt + '').substring(0, 7)+
",y:" + (y/pt + '').substring(0, 7)+
",w:" + (w/pt + '').substring(0, 7)+
",h:" + (h/pt + '').substring(0, 7)+
",color:" + '0-0-0.01-0';
break;
}
} catch(e) {
}
}
writeTxt(stringBuild, get_txt_name() )
function writeTxt(txt, text_path) {//建立函数
var f = new File(text_path);//文件位置
f.open('w');
f.write(txt);
f.close();
}
function isIn(index,shape){
var art = new Artboard(index);
if(art.left> shape.left+shape.width||art.top<shape.top-shape.height||art.right<shape.left||art.bottom>shape.top){
return undefined;
}
return {
'x':shape.left-art.left,
'y':art.height-(art.top-shape.top)-shape.height
};
}
function Artboard(index) {
var doc = app.activeDocument;
/**
* index 下标 (非必填 默认当前画板)
* 画板类用于获取画板的属性
* 宽度,高度,坐标(上下左右垂直中,水平中),简单的信息
*
* 例子
* artboard = Artboard()
* artboard = Artboard(0)
* 打印信息
* alert(artboard.info)
*/
index = index == undefined ? doc.artboards.getActiveArtboardIndex() : index
var abBounds = doc.artboards[index].artboardRect;
this.width = abBounds[2] - abBounds[0];
this.height = abBounds[1] - abBounds[3];
this.left = abBounds[0];
this.top = abBounds[1];
this.bottom = abBounds[3];
this.right = abBounds[2];
this.index = index;
this.toString = function () {
return '当前是第' + index + '个页面\n页面尺寸为' + this.width / pt + 'x' + this.height / pt + ' mm';
}
}
function get_txt_name() {
/**
* 获取文ai路径
* 返回 C:\Users\Administrator\Desktop\hd1024.ai
*/
return get_parent()+'/'+get_name_no_suffix()+'.txt';
}
function get_name_no_suffix() {
/**
* 获取文件名 无后缀
* 返回 hd1024
*/
n = decodeURI(doc.fullName.name);
return n.substring(0, n.lastIndexOf('.'));
}
function get_parent() {
/**
* 获取父路径
* 返回 C:\Users\Administrator\Desktop
*/
return decodeURI(doc.fullName.parent);
}