Skip to main content
d_gualano
Participant
February 18, 2011
Question

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

  • February 18, 2011
  • 2 replies
  • 552 views

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.

This topic has been closed for replies.

2 replies

Harbs.
Legend
February 20, 2011

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

Harbs

Loic.Aigon
Legend
February 18, 2011

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);

     }

        }

}