我有一个InDesign文件,试图通过该脚本编写脚本,但是遇到了问题。我相信文档内容的一部分是从InCopy创建的,因为当我在页面中编写脚本后尝试修改该文本框架时,我会得到:

javascript - 如何修改从InCopy创建的InDesign文档textFrame?-LMLPHP

我没有访问InCopy的权限,并且尝试通过将INDD文件导出到IDML文件然后将其重新带回来覆盖InCopy帧,但无法绕过InCopy。当我研究该站点时,我能找到的最接近的问题是How to script InDesign/InCopy to “Check In” and “Check Out” textFrames?,但是当我尝试对选择内容实施checkOut()时,我得到了一个错误,因此我进行了研究并遇到了:


How to use app.selection[0] for scripts in Adobe InDesign
Indesign script (Javascript) to return/select words around insertion point
SELECTED TEXT FORMATTING


但是我仍然无法在选择文本框中插入。

整理代码

function run() {
    throw new Error( "Script has run into an error" );
}
run.error = null;

try {
    app.doScript( somePages );
    if ( run.error ) {
        throw run.error;
    }
}  catch(e) {
    alert( e );
}

function somePages() {
    var allPages = app.documents[0].pages.everyItem().getElements(),
        items = app.activeDocument.allPageItems,
        pageCount = allPages.length;

    for ( var x = allPages.length-1; x >= 0; x-- ) {
        if ( allPages[x].textFrames.length != 0  && items[x].locked == false ) {
            app.activeDocument.pageItems.everyItem().locked = false;
            app.select(allPages[x].textFrames[0].insertionPoints[0]);
            app.selection[0].contents= "foobar" + allPages[x].name;
        }
    }
}


如何编写文本框脚本,以添加从InCopy创建的文本,从而使我可以浏览文档?

最佳答案

这是因为在文本框的情况下,必须检查的是故事。



function run() {
    throw new Error( "Script has run into an error" );
}
run.error = null;

try {
    app.doScript( somePages );
    if ( run.error ) {
        throw run.error;
    }
}  catch(e) {
    alert( e );
}

function somePages() {
    var allPages = app.documents[0].pages.everyItem().getElements(),
        items = app.activeDocument.allPageItems,
        pageCount = allPages.length;

    for ( var x = allPages.length-1; x >= 0; x-- ) {
        if ( allPages[x].textFrames.length != 0  && items[x].locked == false ) {
			app.activeDocument.stories.everyItem().checkOut();
            app.activeDocument.pageItems.everyItem().locked = false;
            app.select(allPages[x].textFrames[0].insertionPoints[0]);
            app.selection[0].contents= "foobar" + allPages[x].name;
        }
    }
}





app.activeDocument.stories.everyItem()。checkOut();

09-25 18:08