如何在目录中的所有文件上运行Illustrator javascript? [英] How can I run an Illustrator javascript on all files in a directory?

查看:108
本文介绍了如何在目录中的所有文件上运行Illustrator javascript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用javascript来更新Illustrator文件。我有一个脚本,将以所需的方式修改打开的文件(实际上只是文本查找/替换,但文本在Illustrator数据中编码)。问题是我有数百个这样的文件,我想在目录中以相同的方式修改。有没有办法让我这样做而不必打开这些文件中的每一个?

I'm trying to use javascript to update an Illustrator file. 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). 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?

我想要:
1.有一种方法可以修改现有的javascript从目录中读取并在后台加载文件,处理它们,保存和关闭。
2.我可以编写一个可以包装现有Illustrator javascript的Node.js脚本,但我不知道如何让它识别application对象并以与打开时相同的方式读取文件在Illustrator中。

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. 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.

感谢您的帮助!

编辑:这是正常运行的脚本(仅限于此。

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);
}

这篇关于如何在目录中的所有文件上运行Illustrator javascript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆