0 Replies Latest reply on Sep 24, 2016 2:10 AM by Obi-wan Kenobi

    My script doesn't love stories! …

    Obi-wan Kenobi Adobe Community Professional

      Hi all,

       

      I try to transfer all tables of a document in another new document.

      This script [part of a more global script] does it!

       

      //--------------------------------------------------------------------------------------------------------------------------------------------
      
      
      var mySource = app.documents[0];  // here: Source_1story.indd or Source_2stories.indd
      var myTarget = app.documents[1];  // here: Tables-Eps.indd
      
      
      var mySourceStories = mySource.stories.everyItem();
      var mySourceTables = mySourceStories.tables.everyItem().getElements();
      var myTargetPagesNumber = mySourceTables.length;
      
      
      for ( var t = 0; t < mySourceTables.length; t++ )
      {  
               var mySourceTableCharacter = mySourceStories.characters[mySourceTables[t].storyOffset.index];
               var mySourceFrame = mySource.textFrames.add();
      
      
               mySourceFrame.textFramePreferences.autoSizingType = AutoSizingTypeEnum.HEIGHT_AND_WIDTH;
               mySourceFrame.textFramePreferences.autoSizingReferencePoint = AutoSizingReferenceEnum.TOP_LEFT_POINT;
               mySourceFrame.itemLayer = "mySourceLayer";
               mySourceLayer = mySourceFrame.itemLayer ;
      
      
               mySourceTableCharacter.duplicate(LocationOptions.AFTER, mySourceFrame.texts[0].insertionPoints[0]);
      
      
               mySourceLayer.pageItems.everyItem().duplicate(myTarget.pages[t]);  
      
      
               mySourceFrame.remove();
      }
      
      
      //--------------------------------------------------------------------------------------------------------------------------------------------
      
      

       

       

      It works fine if only one story even if it indicates an error:

       

      ErrorMessage.png

       

      The result is weird if several stories!

       

      No idea to fix these 2 issues! 

       

      Thanks for you help!

       

      (^/) 

       

      Dropbox - Test_Files-IDCC2015.zip