1 Reply Latest reply on Nov 12, 2015 11:37 PM by Vamitul

    Export each stories as RTF

    Level 1

      I need to export each and every stories to separate RTF file.


      var myDoc = app.activeDocument;

      var newDoc=app.documents.add();



      for (no_stor=0;no_stor<myDoc.stories.length;no_stor++)


                      var myStory = myDoc.stories[no_stor];


                          alert (app.selection[0])

                          var selText=app.selection[0];



                        //  app.select(new_frame.insertionPoints[new_frame.insertionPoints.length-1]);


                      var nFile=new File(nfolder1+"/"+fName.substring(0,fName.length-4)+"rtf");

                      app.selection[0].exportFile(ExportFormat.RTF, nFile);







      The above code is not wording for me.  It show cannot copy / cut due to invalid selection state.

        • 1. Re: Export each stories as RTF
          Vamitul Level 4


          Should fix it. But your solution as a whole is very very bad!!

          1) why are you using app.select, app.copy and app.paste when you can just use story.duplicate?

          2) why are you creating a new document and copying all the stories in it, instead of just exporting them from the original document?

          how about something like:


          var stories=app.activeDocument.stories.everyItem().getElements();

          for (var i=0; i<stories.length; i++){

             var nFile=new File(nfolder1+"/"+fName.substring(0,fName.length-4)+"rtf");

             stories[i].exportFile(ExportFormat.RTF, nFile);