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);
}
}
}
}
什麼是你的問題/問題? –