2 Replies Latest reply on Feb 19, 2011 11:33 PM by Harbs.

    [CS4 - JS]Export stories and "object is invalid" error

    d.gualano Level 1

      Hello all,

      I need a javascript script that exports all the stories of a document to .icml files.

       

      At the moment I've come to a function like this:

       

      function exportICML(myDoc, path) {

              var stories = myDoc.stories;

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

            alert(i);

            var story = stories.item(i);

            var filename = path + "/story-" + i + ".icml";

            try {

                 story.exportFile(ExportFormat.INCOPY_MARKUP, new File(path));

                   } catch (err) {

      alert(err.message);

           }

              }

      }

       

      This function fails, and in the server log I see this error:

      "Object is invalid"

       

      What am I doing wrong?

       

      Thanks.

        • 1. Re: [CS4 - JS]Export stories and "object is invalid" error
          Loic.Aigon Adobe Community Professional

          Works fine here :S

           

          var myDoc=app.activeDocument;
          var myPath = Folder.desktop+"/test.icml";
          exportICML(myDoc, myPath);

           

          try storing theend of loop outside the function and renaming var to avoid DOM names collision.

           

          function exportICML(myDoc, path) {
                  var allStories = myDoc.stories;
          var iMax = allStories.length;
           for (var i = 0; i < iMax; i++) {
                alert(i);
                var myStory = allStories.item(i);
                var filename = path + "/story-" + i + ".icml";
                try {
                     myStory.exportFile(ExportFormat.INCOPY_MARKUP, new File(path));
                       } catch (err) {
            alert(err.message);
                }
                  }
          }
          
          • 2. Re: [CS4 - JS]Export stories and "object is invalid" error
            Harbs. Level 6

            On which story does it fail? Maybe you have an empty story which it can't export?

             

            Harbs