代码如下:
PHP 代码:
// 获取当前文档
var doc = app.activeDocument;
// 创建一个文件夹,用于存放统计信息
var folder = new Folder(Folder.desktop + "/illustrator_stats");
if (!folder.exists) folder.create();
// 创建一个文件,用于存放统计信息
var file = new File(folder.fsName + "/stats.txt");
// 初始化文件
file.open("w");
file.encoding = "UTF-8";
// 写入文件头
file.writeln("Illustrator Stats"); file.writeln("=================");
// 统计字体
file.writeln("未转曲字体:");
var fonts = {};
for (var i = 0; i < doc.textFrames.length; i++) {
var textFrame = doc.textFrames[i]; for (var j = 0; j < textFrame.characters.length; j++) {
var font = textFrame.characters[j].textFont;
if (fonts[font.name] == undefined) {
fonts[font.name] = 1;
} else { fonts[font.name]++; }
}
} for (var fontName in fonts) {
file.writeln(" " + fontName + ": " + fonts[fontName]);
}
// 统计颜色
file.writeln("色板中颜色:");
var colors = {};
for (var i = 0;
i < doc.swatches.length; i++) {
var swatch = doc.swatches[i]; if (colors[swatch.name] == undefined) {
colors[swatch.name] = 1;
} else { colors[swatch.name]++; }
}
for (var colorName in colors) {
file.writeln(" " + colorName + ": " + colors[colorName]);
}
// 统计图片
file.writeln("外链图片:");
var images = {};
for (var i = 0; i < doc.placedItems.length; i++) {
var placedItem = doc.placedItems[i];
if (images[placedItem.file.name] == undefined) {
images[placedItem.file.name] = 1;
} else { images[placedItem.file.name]++; }
} for (var imageName in images) {
file.writeln(" " + imageName + ": " + images[imageName]);
}
// 关闭文件
file.close();
file.execute();