【问题标题】:Error Running jsx file from Indesign to export each text frame as a .txt file从 Indesign 运行 jsx 文件以将每个文本框架导出为 .txt 文件时出错
【发布时间】:2015-07-15 15:20:02
【问题描述】:

去年我的同事帮助为 Indesign 构建了一个脚本。

随后,在系统更新后,我们不再拥有该脚本,因为重新安装了 Indesign CS6,我们只有一个版本如下。

在 Adob​​e Indesign 中使用此代码导出以特定段落样式表“PRODUCT HEADING”开头的每个文本框架,但是当我运行脚本时收到错误消息...

脚本基于与 InDesign 捆绑的 ExportAllStories.jsx,以及一些在线找到的模块。

//ExportAllStories.jsx
//An InDesign CS6 JavaScript
/*  
@@@BUILDINFO@@@ "ExportAllStories.jsx" 3.0.0 15 December 2009
*/
//Exports all stories in an InDesign document in a specified text format.
//
//For more on InDesign scripting, go to http://www.adobe.com/products/indesign/scripting/index.html
//or visit the InDesign Scripting User to User forum at http://www.adobeforums.com
//
main();
function main(){
    //Make certain that user interaction (display of dialogs, etc.) is turned on.
    app.scriptPreferences.userInteractionLevel = UserInteractionLevels.interactWithAll;
    if(app.documents.length != 0){
        if (app.activeDocument.stories.length != 0){
            myDisplayDialog();
        }
        else{
            alert("The document does not contain any text. Please open a document containing text and try again.");
        }
    }
    else{
        alert("No documents are open. Please open a document and try again.");
    }
}
function myDisplayDialog(){
    with(myDialog = app.dialogs.add({name:"ExportAllStories"})){
        //Add a dialog column.
        myDialogColumn = dialogColumns.add()    
        with(myDialogColumn){
            with(borderPanels.add()){
                staticTexts.add({staticLabel:"Export as:"});
                with(myExportFormatButtons = radiobuttonGroups.add()){
                    radiobuttonControls.add({staticLabel:"Text Only", checkedState:true});
                    radiobuttonControls.add({staticLabel:"RTF"});
                    radiobuttonControls.add({staticLabel:"InDesign Tagged Text"});
                }
            }
        }
        myReturn = myDialog.show();
        if (myReturn == true){
            //Get the values from the dialog box.
            myExportFormat = myExportFormatButtons.selectedButton;
            myDialog.destroy;
            myFolder= Folder.selectDialog ("Choose a Folder");
            if((myFolder != null)&&(app.activeDocument.stories.length !=0)){
                myExportAllStories(myExportFormat, myFolder);
            }
        }
        else{
            myDialog.destroy();
        }
    }
}
//myExportStories function takes care of exporting the stories.
//myExportFormat is a number from 0-2, where 0 = text only, 1 = rtf, and 3 = tagged text.
//myFolder is a reference to the folder in which you want to save your files.
function myExportAllStories(myExportFormat, myFolder){
    for(myCounter = 0; myCounter < app.activeDocument.stories.length; myCounter++){
        myStory = app.activeDocument.stories.item(myCounter);
        myID = myStory.id;
        switch(myExportFormat){
            case 0:
                myFormat = ExportFormat.textType;
                myExtension = ".txt"
                break;
            case 1:
                myFormat = ExportFormat.RTF;
                myExtension = ".rtf"
                break;
            case 2:
                myFormat = ExportFormat.taggedText;
                myExtension = ".txt"
                break;
        }
        if (myStory.paragraphs[0].appliedParagraphStyle.name == "PRODUCT HEADING"){

              myFileName = myFileName.replace(/\s*$/,' ');
              myFileName2 = myFileName.replace(/\//g, ' ');
              myFilePath = myFolder + "/" + myFileName2;
            myFile = new File(myFilePath);
            myStory.exportFile(myFormat, myFile);
        }
    }
}

这会导致错误

        if (myStory.paragraphs[0].appliedParagraphStyle.name == "PRODUCT HEADING"){

任何建议将不胜感激。

Indesign 文件中肯定有一段带有 PRODUCT HEADING(全部大写)样式的文本。我们像以前一样运行 Indesign CS6

谢谢!

【问题讨论】:

    标签: text output adobe-indesign paragraph


    【解决方案1】:

    您的问题很可能与这部分有关:myStory.paragraphs[0]。如果故事没有段落,这会给你一个错误。 您可以在运行此行之前添加一个条件,例如:

    if(myStory.paragraphs.length){
        if (myStory.paragraphs[0].appliedParagraphStyle.name == "PRODUCT HEADING"){
    
                myFileName = myFileName.replace(/\s*$/,' ');
                myFileName2 = myFileName.replace(/\//g, ' ');
                myFilePath = myFolder + "/" + myFileName2;
                myFile = new File(myFilePath);
                myStory.exportFile(myFormat, myFile);
            }
    }
    

    【讨论】:

    • 感谢 Julien,我现在已经更正了我们正在使用的代码并将其添加到上面的原始帖子中,如果将来对其他人有用...
    • @PeteCardwell:请不要(我回滚了那个编辑)。 Stack Overflow 的目的是成为一个问题/答案站点,因此编辑您的 问题 以包含 答案 并不是很有用。如果您的工作版本与 Julien 建议的版本大不相同,您可以随时将其添加为适当的替代答案。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-22
    • 2022-01-20
    • 2013-06-22
    相关资源
    最近更新 更多