2016-10-18 60 views
0

我有下面幾年已編輯過的腳本。indesign javascript導出文本循環

我創建了一個循環來遍歷每種語言。運行循環可以隱藏和顯示每種語言的效果。每當我運行腳本調用我的循環中的主函數時,它會在英文之後停止。

我知道這個腳本會做些什麼,但它已經被編輯了幾年,以適應不斷變化的需求,我不是開發者。

var languages = ['ENGLISH', 'FRENCH', 'DUTCH', 'ITALIAN', 'GERMAN']; 


for(var i=0;i<languages.length;i++){ 
    myFunction(languages[i]); 
} 

function myFunction(value) { 
    if (value == 'ENGLISH') { 
     app.activeDocument.conditions.item("ENGLISH").visible = true; 
     app.activeDocument.conditions.item("FRENCH").visible = false; 
     app.activeDocument.conditions.item("DUTCH").visible = false; 
     app.activeDocument.conditions.item("ITALIAN").visible = false; 
     app.activeDocument.conditions.item("GERMAN").visible = false; 

} 
if (value == 'FRENCH') { 
    app.activeDocument.conditions.item("ENGLISH").visible = false; 
    app.activeDocument.conditions.item("FRENCH").visible = true; 
    app.activeDocument.conditions.item("DUTCH").visible = false; 
    app.activeDocument.conditions.item("ITALIAN").visible = false; 
    app.activeDocument.conditions.item("GERMAN").visible = false; 

} 
if (value == 'DUTCH') { 
    app.activeDocument.conditions.item("ENGLISH").visible = false; 
    app.activeDocument.conditions.item("FRENCH").visible = false; 
    app.activeDocument.conditions.item("DUTCH").visible = true; 
    app.activeDocument.conditions.item("ITALIAN").visible = false; 
    app.activeDocument.conditions.item("GERMAN").visible = false; 

}  
if (value == 'ITALIAN') { 
    app.activeDocument.conditions.item("ENGLISH").visible = false; 
    app.activeDocument.conditions.item("FRENCH").visible = false; 
    app.activeDocument.conditions.item("DUTCH").visible = false; 
    app.activeDocument.conditions.item("ITALIAN").visible = true; 
    app.activeDocument.conditions.item("GERMAN").visible = false; 

}  
if (value == 'GERMAN') { 
    app.activeDocument.conditions.item("ENGLISH").visible = false; 
    app.activeDocument.conditions.item("FRENCH").visible = false; 
    app.activeDocument.conditions.item("DUTCH").visible = false; 
    app.activeDocument.conditions.item("ITALIAN").visible = false; 
    app.activeDocument.conditions.item("GERMAN").visible = true; 

} 

main(value); 
} 

function main(language){ 
    //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(language); 
    } 
    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(language){ 
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, language); 
     } 
    } 
    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, language){ 
    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.length){ 
if (myStory.paragraphs[0].appliedParagraphStyle.name == "PRODUCT HEADING"){ 

     myFileName = myStory.paragraphs[0].contents.replace(/\s*$/,''); 
     myFileName2 = myFileName.replace(/\//g, ' '); 
     myFilePath = myFolder + "/" + language + '_' + myFileName2 + myExtension; 
     myFile = new File(myFilePath); 
     myStory.exportFile(myFormat, myFile); 


    } 
} 
} 
} 
+0

什麼是你的問題/問題? –

回答

0

也許其他條件不存在或「產品標題」段落樣式不適用於本地化的條件文本。

ANYWAY這裏是一種方法,旨在緩解事情的一點點,使東西更加保持良好。

var main = function(language) { 
 
\t var doc = app.properties.activeDocument; 
 
\t 
 
\t if (!doc) return; 
 
\t 
 
\t displayCondition(doc,language); 
 
\t myDisplayDialog(language); 
 
} 
 

 
var displayCondition = function(doc, language) { 
 
\t var myCond = doc.conditions.itemByName (language); 
 
\t if (!myCond.isValid) return; 
 
\t doc.conditions.everyItem().visible = false; 
 
\t myCond.visible = true; 
 
} 
 

 
var u; 
 

 
app.doScript ("main('DUTCH')",u,u,UndoModes.ENTIRE_SCRIPT, "The Script"); 
 

 

 
function myDisplayDialog(language){ 
 
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, language); 
 
     } 
 
    } 
 
    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, language){ 
 
    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.length){ 
 
if (myStory.paragraphs[0].appliedParagraphStyle.name == "PRODUCT HEADING"){ 
 

 
     myFileName = myStory.paragraphs[0].contents.replace(/\s*$/,''); 
 
     myFileName2 = myFileName.replace(/\//g, ' '); 
 
     myFilePath = myFolder + "/" + language + '_' + myFileName2 + myExtension; 
 
     myFile = new File(myFilePath); 
 
     myStory.exportFile(myFormat, myFile); 
 

 

 
    } 
 
} 
 
} 
 
}

HTH

+0

謝謝,由於某種原因,我今天早上的作品,我不明白爲什麼...... –