[英]How can I run an Illustrator javascript on all files in a directory?
I'm trying to use javascript to update an Illustrator file. 我正在尝试使用JavaScript更新Illustrator文件。 I have a script that will modify an open file in the desired way (really just a text find/replace, but the text is encoded in the Illustrator data).
我有一个脚本,该脚本将以所需的方式修改打开的文件(实际上只是查找/替换文本,但文本是在Illustrator数据中编码的)。 The problem is I have hundreds of these files that I want modified in the same way in a directory.
问题是我在目录中有数百个要以相同方式修改的文件。 Is there a way for me to do this without having to open every single one of these files?
有没有办法让我不必打开这些文件中的每个文件?
I figure either: 1. there's a way to modify the existing javascript to read from the directory and load the files in the background, process them, save, and close. 我认为:1.有一种方法可以修改现有的javascript,以从目录中读取并在后台加载文件,对其进行处理,保存并关闭。 2. I can write a Node.js script that can wrap the existing Illustrator javascript, but I'm not sure how to get it to recognize the "application" object and read the file the same way as when it's opened in Illustrator.
2.我可以编写一个可以包装现有Illustrator javascript的Node.js脚本,但是我不确定如何获取它来识别“应用程序”对象并以与在Illustrator中打开文件相同的方式读取文件。
Thanks for any help! 谢谢你的帮助!
Edit: Here's the functioning script (that only . 编辑:这是起作用的脚本(仅此脚本。
function FindAndReplaceScript_AllOpenDocuments(){
for(var i=app.documents.length -1; i > -1; i--){
app.documents[i].activate();
var aDoc = app.documents[i];
var searchString = /OLDTEXT/gi;
var replaceString = 'NEWTEXT';
var theTF = aDoc.textFrames;
if (theTF.length > 0) {
for (var j = 0 ; j <theTF.length; j++) {
var aTF = theTF[j];
var newString = aTF.contents.replace(searchString, replaceString);
if (newString != aTF.contents) {
theTF[j].contents = newString;
}
}
}
}
};
FindAndReplaceScript_AllOpenDocuments();
}
Yes,there is a way to read from directory: 是的,有一种从目录读取的方法:
var dir = Folder.selectDialog("Where?");
var files = dir.getFiles("*.eps");
for(var f = 0; f < files.length; f++){
var doc = app.open(files[f]);
//Your processing
doc.close(SaveOptions.SAVECHANGES);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.