简体   繁体   English

如何在目录中的所有文件上运行Illustrator javascript?

[英]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.

相关问题 如何动态加载和执行目录中的所有JavaScript文件的? - How can I dynamically load and execute all of the Javascript files in a directory? 如何在运行时使用javascript将illustrator的svg添加到DOM? - How can I use javascript to add svg from illustrator to the DOM at run-time? 如何使用脚本关闭 Illustrator 中所有打开的文档? - How can I close all open documents in illustrator with script? 如何通过 JavaScript 文件将所有 JavaScript 文件包含在目录中? - How can I include all JavaScript files in a directory via JavaScript file? 我可以使用JavaScript在目录中的所有xml文件中搜索字符串吗? - Can I search all xml files in a directory for a string using javascript? 如何在Illustrator中打开PDF文件数组,而无需用户使用javascript / extendscript确认提示? - How do I open an array of PDF files in Illustrator without user confirmation of prompts using javascript/extendscript? 运行目录中的所有文件 - Run all files in a directory 如何返回目录文件? (JavaScript,Node.js) - How can I return the files of a directory? (JavaScript, Node.js) JavaScript - 如何在所有 html 行中运行 javascript - JavaScript - How can I run the javascript in all my html rows 如何在目录中查找所有文件? (HTML JavaScript) - How to find all files in directory? (HTML JavaScript)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM