首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >f[i].insertionPoints[0].rectangles.add({geometricBounds:

f[i].insertionPoints[0].rectangles.add({geometricBounds:
EN

Stack Overflow用户
提问于 2017-07-16 08:31:34
回答 1查看 257关注 0票数 0

我正在拼命地为我的问题寻找解决方案。我需要用这个脚本在InDesign中放置大量的内联图形,但由于某些原因它不能工作。我对Javascript知之甚少,而且我的时间不多了,所以我不能花太多的时间学习JS。我在InDesign CC2014和约塞米蒂一起做iMac。

弹出以下错误消息:

错误快照:

如果有人能帮我一把,我会很高兴的。

代码语言:javascript
运行
复制
main();

function main() {
var name, f, file, text,
arr = [];

if(app.documents.length != 0) {
    var doc = app.activeDocument;   
    var folder = Folder.selectDialog("Choose a folder with images");

    if (folder != null) {
        app.findObjectPreferences = app.changeGrepPreferences  = NothingEnum.NOTHING;
        app.findGrepPreferences.findWhat = "@.+?@";
        f = doc.findGrep(true);

        for (i = 0; i < f.length; i++) {
            name = f[i].contents.replace(/@/g, "");
            file = new File(folder.fsName + "/" + name);

            if (file.exists) {
                f[i].contents = "";
                var rect = f[i].insertionPoints[0].rectangles.add({geometricBounds:[0,0, 60, 40.667 ]} );
				rect.place ( file );
				rect.fit ( FitOptions.FRAME_TO_CONTENT);
                
            }
            else {
                arr.push("File doesn't exist '" + name + "'");
            }
        }

        app.findObjectPreferences = app.changeGrepPreferences  = NothingEnum.NOTHING;

        arr.push("------------------------------------------");
        text = arr.join("\r");
        writeToFile(text);
    }
}
else{
    alert("Please open a document and try again.");
}   
}

function writeToFile(text) {
var file = new File("~/Desktop/Place inline images.txt");
if (file.exists) {
    file.open("e");
    file.seek(0, 2);
}
else {
    file.open("w");
}
file.write(text + "\r"); 
file.close();
}

EN

回答 1

Stack Overflow用户

发布于 2017-07-17 18:31:35

问题可能是脚本正在编辑找到的内容,并在接下来的代码行中引用它。我建议使用反向循环,并将fi.contents = ""移到后面的行。

类似于:

代码语言:javascript
运行
复制
main();

function main() {
var name, f, cF, file, text,
arr = [];

if(app.documents.length != 0) {
    var doc = app.activeDocument;   
    var folder = Folder.selectDialog("Choose a folder with images");

    if (folder != null) {
        app.findObjectPreferences = app.changeGrepPreferences  = NothingEnum.NOTHING;
        app.findGrepPreferences.findWhat = "@.+?@";
        f = doc.findGrep(true);

       while(cF = f.pop()) {
            name = cF.contents.replace(/@/g, "");
            file = new File(folder.fsName + "/" + name);

            if (file.exists) {
                var rect = cF.insertionPoints[0].rectangles.add({geometricBounds:[0,0, 60, 40.667 ]} );
                rect.place ( file );
                rect.fit ( FitOptions.FRAME_TO_CONTENT);
                cF.contents = "";
            }
            else {
                arr.push("File doesn't exist '" + name + "'");
            }
        }

        app.findObjectPreferences = app.changeGrepPreferences  = NothingEnum.NOTHING;

        arr.push("------------------------------------------");
        text = arr.join("\r");
        writeToFile(text);
    }
}
else{
    alert("Please open a document and try again.");
}   
}

function writeToFile(text) {
var file = new File("~/Desktop/Place inline images.txt");
if (file.exists) {
    file.open("e");
    file.seek(0, 2);
}
else {
    file.open("w");
}
file.write(text + "\r"); 
file.close();
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45123913

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档