1 Reply Latest reply on Nov 6, 2009 4:14 AM by Peter Kahrel

    Help with Altering a Script

    jcapes1

      Hi,

       

      I am very new to scripting and have been trying to alter this script, to return information for stories. I would like the final .txt to show StoryID and Page Number for each story.

       

       

      I thought I could replace all ".links" with ".stories" add "Story ID" and have a working script, but that was not the case.
      I tried many variations, one even gave me the story id but not page numbers.

      This version may be the closest although it has some extra stuff and does not work.


      //DESCRIPTION: Exports some information about stories in the active Document into a textfile in the same folder as the document. 
      // The values are tab-separated, so that the content of the file can be copied to Excel via Clipboard.
      // The exported textfile has the ending ".txt".
      // Based off of  the LinkExportPro script by Martin Fischer (www.hilfdirselbst.ch)
      //
      var myDoc = app.documents[0];
      if (myDoc.saved == false)
      {
           alert("Error.\rYou must first save your document.");
           exit();
      }
      var myDocName = myDoc.name.split(".indd")[0];
      var myTXT_File = myDocName + '.txt';
      var myPath = myDoc.filePath + "/";
      var myCreator = "R*ch";      
      var myType = "TEXT"; 
      var theFiles = myDoc.stories;
      var StoryID = Story.id
      var myData = "ID\tpage\r";      

      var f = new File( myPath + myTXT_File ); 
      f.open( 'w', myType, myCreator ); 
      f.writeln( myData ); 

      for (myCounter = 0; myCounter<theFiles.length;myCounter ++ ) { 
           }
           var myClass = theFiles[myCounter].parent.parent.parent.constructor.name;
           // text placed on page
           if (myClass == "Page") 
           { 
                myPage = theFiles[myCounter].parent.parent.parent.name;
           } 
           // image embedded
           else if (myClass == "Character")
           {
                try 
                {     
                     myPage = theFiles[myCounter].parent.parent.parent.parentTextFrames[0].parent.name;
                }
                catch(e)
                {
                     myPage = "versteckt im ´┐Żberlauf";
                }
           } 
           else {
                try 
                { 
                     // image placed outside the pages
                     myPage = "Spread of " + theFiles[myCounter].parent.parent.parent.pages[0].name;
                } 
                catch(e) 
                { 
                     // don't know the page where the image is placed
                     alert ("Class: " + myClass + "\r" + theFiles[myCounter].name);
                } 
           } 
           myData = theFiles[myCounter].name + "\t" + StoryID + "\t" + myPage + "\r";
           f.writeln(myData); 

      f.close();



      I am getting an "Object is invalid" error for
           var myClass = theFiles[myCounter].parent.parent.parent.constructor.name;
      but I know that is not the only problem.

      Any advice will be appreciated.





      Thanks.


      JC