I found a script on the Indesign CD that enables you to export all stories (ExportAllStories.js)
When you export the all the stories it gives each file a name e.g
StoryID21665.rtf
I need to translated all these files and I would like to know if there is any tool or script that could import them all again so that I wouldn't have to do it one by one.
Also, is it possible for me to change the StoryID before I export so that could maybe call the first story
StoryID1.rtf
instead of
StoryID21665.rtf
If anyone knows of any other scripts that allow you to import export stories in batches i would also be grateful to hear about them
CP
}
myFileName = "StoryID" + myID + myExtension;
myFilePath = myFolder + "/" + myFileName;
myFile = new File(myFilePath);
myStory.exportFile(myFormat, myFile);
}
But I don't know how you would change it.
> I need to translated all these files and I would like to know if there
> is any tool or script that could import them all again so that I
> wouldn't have to do it one by one.
I posted an AppleScript version here a while back.
>
> Also, is it possible for me to change the StoryID before I export so
> that could maybe call the first story
> StoryID1.rtf
> instead of
> StoryID21665.rtf
Not really.
--
Shane Stanley <ssta...@myriad-com.com.au>
I searched and found the code but i have been working with the .js script that comes with the IndesignCS CD and i am working in PC. So the MAC script doesn't really help.
Does anyone have a script for PC
"The Story object, oddly enough, doesn't have a Place method. But you can replace the text of the story using something like this:"
Rem Given a reference to a story "myStory" and a file path "myFileName"
myStory.Texts.Item(1).Place myFileName
Can anyone help me out here?
CP
The example you've cited is VBScript; if you're working with JavaScript, you'll need to change a few things. JavaScript is case sensitive, so:
myStory.texts.item(0).place(File(myFileName));
The point of tagging each story with the id of the story on export was to make possible exactly what you're talking about--exporting, then re-importing all of the text. The nice thing about using the ID property of the story in the name of the file is that the ID is unique--we can go back to the original document, find a story, check its ID, and we then know which exported file should replace it. We can't do that if we use the index, because the index of the story can change.
Thanks,
Ole
Do I just add the code to the last line of the ExportAllStories script on the CD like below or am I misunderstanding something?:
myFileName = "StoryID" + myID + myExtension;
myFilePath = myFolder + "/" + myFileName;
myFile = new File(myFilePath);
myStory.exportFile(myFormat, myFile);
myStory.texts.item(0).place(File(myFileName));
}
}
CP
That would replace the text of the first story with the text of the exported story over and over again. I don't think that's what you want to do--what I think you want to do is:
1. Export all of the stories.
2. Translate all of the exported stories, saving back to the same file names.
3. Replace the stories in the document with the translated versions.
Right?
If this is the case, you'd use the ExportAllStories script, then use another script to replace the stories after they are translated. If that's what you want, I can post an example.
Thanks,
Ole
Yes please.
I have heard that you can export all stories and then link the files after export.So once you have translated you can just update the links. Is that what your code does?
Anyway the code will still be appreciated.
CP
It could! That's what I'll have it do in the example.
Note, however, that if you choose to export as plain text, you'll lose all formatting when you update the link; if you use RTF, some formatting might not be retained, but it's a better choice. Tagged Text will retain all of the formatting (it's supposed to, at least), but it would be very difficult to translate.
Thanks,
Ole
Thanks, I look forward to it.
CP
your examle I mean this code:below export all story is strange for me
myStory.exportFile(myFormat, myFile);
so I can't find it in standard documentation InDesignCS , need I some
additionall dll or something like this ?
Peter
It is on the Indesign CS CD. The script's name is ExportAllStories
I don't really know anything about scripts so I can't really answer but I am hoping Ole will be around soon as he has a solution to the script
CP
This version exports all of the stories, then re-imports and links to the stories. Note that RTF cannot capture all of the formatting used in an InDesign story, so some of your formatting might change. If, on the other hand, you use tagged text, the process of translating the text will become much more difficult. You'll also have problems if your stories contain inline frames or tables.
Those disclaimers aside, here's a version that (I think) does what you want:
//ExportAndLinkAllStories.js
//An InDesign CS JavaScript
//
//Exports all stories in an InDesign document in a specified text format and links the exported stories to the document.
//
//For more on InDesign scripting, go to <http://www.adobe.com/products/indesign/scripting.html>
//or visit the InDesign Scripting User to User forum at <http://www.adobeforums.com>
//
if(app.documents.length != 0){
if (app.activeDocument.stories.length != 0){
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:"RTF", checkedState:true});
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);
myLinkAllStories(myFolder);
}
}
myDialog.destroy();
}
}
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.");
}
//myExportStories function takes care of exporting the stories.
//myExportFormat is a number from 0-1, where 0 = rtf, and 1 = 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.RTF; myExtension = ".rtf" break; case 1: myFormat = ExportFormat.taggedText; myExtension = ".txt" break; } myFileName = "StoryID" + myID + myExtension; myFilePath = myFolder + "/" + myFileName; myFile = new File(myFilePath); myStory.exportFile(myFormat, myFile); } } //Replace and link to the exported files. function myLinkAllStories(myFolder){ app.activeDocument.textPreferences.linkTextFilesWhenImporting = true; for(myCounter = 0; myCounter < app.activeDocument.stories.length; myCounter++){ myStory = app.activeDocument.stories.item(myCounter); myID = myStory.id;
myFileName = "StoryID" + myID + myExtension;
myFilePath = myFolder + "/" + myFileName;
myFile = new File(myFilePath);
myStory.texts.item(0).place(myFile);
}
}
Thanks,
Ole
The @!#$ stupid forum formatting defeats me, as usual. I have tried more than tem times now to get the code in the above example to break correctly, but it refuses to do so (makes me wonder what they think "<pre>" is supposed to mean). Anyway, please break the last "for" loop at the opening brace ("{") and after each semicolon.
Thanks,
Ole
I think I fixed it. You have to avoid the use of < Either restructure your code, e.g.:
for (i=0; myLim > i; i++) {
or after posting, edit each < replacing with <
Dave
Thanks for the fix! It looks fine now. I generally change the less than sign to the HTML version, but I missed that one (repeatedly!<g>).
Ole
Thanks, I think have it working. You said
"You'll also have problems if your stories contain inline frames or tables. "
Is this the case when also saving to RTF? After running the script. Some of the tables I had have got little red dots in them. Usually in the top left hand corner.
CP
The little red dots mean that the cell is too small to hold the text it contains (they're like the overset marker on a text frame).
Yes, it's most likely that this is a result of the formatting changing in the export/import process. Try selecting the table cells in question and re-applying the formatting.
I'm actually somewhat surprised that the tables exported to RTF at all, so, while there are going to be some problems, this is basically good news.
Thanks,
Ole
It is very poosible though that the attributes of the table itself (strokes, insets etc.) will change
As most of us translators would use Trados (translation memory tool) to do an analysis of the exported files to get a word count, this will not work. For some reason, you have to open each file and “save as” for it to work.
Everytime I tried to analyse the files without saving as, the word count from Trados was totally wrong (less than 50% of what it should have been). Also, when I tried to translate the exported files from the translation memory it would completely skip text and also strip the paragraph of its style.
I don’t know what happens when you “save as” but this is the only way to make the files stable. Naturally of cause you have to save them back to what they were originally called, after tranlsation, in order for the links to be updated in Indesign.
Another thing I also noticed was that if you open one of the exported files and try to change the style name, you can’t. So there is definitely something strange about the state of the file before you “save as”.
Maybe someone here can explain.
Anyway, thanks Ole for your time as you have saved me plenty of hours of copying and pasting in the future
CP
In what application are you trying to edit the style names, and from what application do you choose "save as"?
Have also tried it on MS Word 2002
CP
It's probably that Trados expects the RTF to be RTF exactly as exported by Word. Opening the files in Word and doing a save as is probably the only thing we can do, at this point.
Word can be scripted to do this. I don't have time right now to take it on, but I should be able to get back to it next week.
Thanks,
Ole